in src/Frontend/src/services/auth.ts [44:84]
export async function googleSignIn(firebaseAuth : Auth) : Promise<IAuthSigninResponse | null> {
return new Promise<IAuthSigninResponse | null>(async (resolve, reject) => {
try {
// Sign in using a popup.
const provider = new GoogleAuthProvider();
provider.setCustomParameters({ prompt:'select_account' });
provider.addScope('profile');
const result : (UserCredential | void) = await signInWithPopup(firebaseAuth, provider).catch(error => {
if (process.env.NODE_ENV === 'development') console.error('[FIREBASE GOOGLE AUTH ERROR]: ' + error);
AlertInstance.alert(ALERT_ERROR, "error_google_auth")
reject(null);
});
if (!result) return reject(null);
const user : (User | any) = result.user;
const { email } = user;
const bodyData = { token: user.accessToken };
await api.post(ENDPOINT_AUTH_TOKEN, bodyData).then(response => {
const { id, access_token, refresh_token, token_type, scopes, user_name, user_id } = response.data;
resolve({
id,
access_token,
refresh_token,
token_type,
scopes,
email,
user_name,
user_id
});
});
} catch (e) {
if (process.env.NODE_ENV === 'development') console.error('[PROMISE ERROR]: ' + e);
AlertInstance.alert(ALERT_ERROR, 'toast.errors.auth.error_auth');
reject(null);
}
});
}