I’m making an app with expo and I want to authenticate in the app using email/password or using google.
I added email and password authentication using this code:
// this is the function for initiating firebase
function init_firebase(){
const firebaseConfig = {
apiKey: ' AIzaSyCs-qNMrjikN5VqKdY737K22QSsT9MmtGI ',
authDomain: 'tiod-app.firebaseapp.com',
databaseURL: 'https://tiod-app-default-rtdb.europe-west1.firebasedatabase.app/',
projectId: 'tiod-app',
appId: '1:659850692368:android:bf812065131d214dfb0795',
};
const app = initializeApp(firebaseConfig);
const auth = initializeAuth(app, {
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
});
return {app, auth};
}
export const firebase = init_firebase();
and
// the function for signing up
async function Signup_email(navigation: NavigationProp<ParamListBase>, email: string, password: string){
const login = await createUserWithEmailAndPassword(firebase.auth, email, password).catch((e) => {
console.log(e);
});
if (login){return;}
navigation.navigate('Main', {email});
}
// the function for logging in
async function Login_email(navigation: NavigationProp<ParamListBase>, email: string, password: string,
){
const app = firebase;
if (!app){return;}
const login = await signInWithEmailAndPassword(app.auth, email, password).catch((e) => {console.log(e)});
if (!login){return;}
navigation.navigate('Loading', login.user.toJSON());
}
and it worked well, but for authentication with google, I realized that the function that is used for redirecting to sign in (which is signInWithRedirect
) is undefined since it affects the DOM.
so I used @react-native-google-signin/google-signin
to attempt to do the same thing. I managed to
use google to sign in using this code:
async function Login_google(navigation: NavigationProp<ParamListBase>){
const result = await GoogleSignin.signIn().catch((e) => {console.log(e)});
if (!result){return;}
navigation.navigate('Loading', result.user);
}
also, I configured google signin in main
GoogleSignin.configure({webClientId: "659850692368-bf2itlqkbbroq5cd3e8lq969qtk8ks5i.apps.googleusercontent.com",
googleServicePlistPath: "../GoogleService-Info.plist",
})
but for some reason, after logging in with google the user dashboard in firebase is still empty
throwaway account is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.