Я следил за настройкой Firebase, добавил мой Google-services.json из проекта OAuth и интегрировал плагин. Выбор, я получаю эту ошибку времени выполнения на Android: < /p>
Попытка вызвать виртуальный метод
void io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.googleauthproviderhandler.signin (...) '
on a null объект.// src/firebase.js
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
const firebaseConfig = {
apiKey: "add key here",
authDomain: "my-app.firebaseapp.com",
projectId: "my-app-id",
storageBucket: null,
messagingSenderId: "Project number in firebase",
appId: "id get from android app in firebase",
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
< /code>
// login handler
import { FirebaseAuthentication } from '@capacitor-firebase/authentication';
import { GoogleAuthProvider, signInWithCredential } from 'firebase/auth';
import { auth } from '../../firebase';
const handleGoogleLogin = async () => {
try {
const result = await FirebaseAuthentication.signInWithGoogle();
if (!result.credential?.idToken) {
alert('No idToken returned');
return;
}
const credential = GoogleAuthProvider.credential(result.credential.idToken);
const firebaseUserCredential = await signInWithCredential(auth, credential);
const user = firebaseUserCredential.user;
alert(`user.uid: ${user.uid}, email: ${user.email}`);
} catch (err) {
alert('Error occurred: ' + JSON.stringify(err, Object.getOwnPropertyNames(err)));
console.error('Google Sign-In Error:', err);
}
};
< /code>
dependencies Versions
"@capacitor-firebase/authentication": "^6.3.1",
"@capacitor/android": "^6.0.0",
"@capacitor/app": "^6.0.2",
"@capacitor/core": "^6.2.1",
"@capacitor/haptics": "6.0.0",
"@capacitor/ios": "^6.0.0",
< /code>
android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
implementation "com.google.android.gms:play-services-auth:20.7.0"
implementation platform('com.google.firebase:firebase-bom:34.2.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
< /code>
android/build.gradle
dependencies {
classpath "com.android.tools.build:gradle:8.2.2"
classpath 'com.google.gms:google-services:4.4.2'
}
< /code>
Сообщение об ошибке < /p>
Вопрос < /p>
Что мне не хватает в моей настройке?
Должен ли я добавить как SHA-1, так и SHA-256 отпечатков пальцев в Firebase? /> Почему плагин возвращает NULL при вызове SignInWithGoogle ()? < /p>
контекст (что вы создаете).
Что вы пробовали (настройка Firebase + oauth). /> Четкий вопрос в конце.
, который пройдет фильтр «Не только код».>
Подробнее здесь: https://stackoverflow.com/questions/797 ... s-googleau
Мобильная версия