Migrating to RN-Firebase v22 #8419
Unanswered
Rakshitg600
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Help me with this error please.
Property 'credential' does not exist on type 'FirebaseModuleWithStaticsAndApp<Module, Statics>'.ts(2339)
Error Snippet:
import GoogleAuthProvider,{ getAuth, signOut, onAuthStateChanged } from '@react-native-firebase/auth';
const auth = getAuth();
const googleCredential = GoogleAuthProvider.credential(idToken);
const userCredential = await getAuth().signInWithCredential(googleCredential);
Whole Code:
import { GoogleSignin } from '@react-native-google-signin/google-signin';
import GoogleAuthProvider,{ getAuth, signOut, onAuthStateChanged } from '@react-native-firebase/auth';
GoogleSignin.configure({
webClientId: WEB_CLIENT_ID,
});
const auth = getAuth();
const App = () => {
const [user, setUser] = useState(null);
useEffect(() => {
const subscriber = onAuthStateChanged(auth, (usr: any) => {
setUser(usr);
});
return subscriber;
}, []);
const handleSignOut = async () => {
try {
await GoogleSignin.signOut();
await signOut(auth);
setUser(null);
} catch (error) {
console.error('Sign out error:', error);
}
};
const handleSignIn = async () => {
try {
await GoogleSignin.hasPlayServices();
await GoogleSignin.signIn();
const { idToken } = await GoogleSignin.getTokens();
if (!idToken) {
throw new Error("Google Sign-In failed: No ID Token received.");
}
const googleCredential = GoogleAuthProvider.credential(idToken);
const userCredential = await getAuth().signInWithCredential(googleCredential);
const currentUser = userCredential.user;
setUser(currentUser);
} catch (error) {
console.error('Google Sign-In error:', error);
}
};
return (<></>);
};
Beta Was this translation helpful? Give feedback.
All reactions