Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const onGoogleLogin = useCallback(async () => {
if (isStandaloneAndAndroid()) {
// TODO: AndroidのstandaloneのみGoogleSignInを使わないとエラーになる
// https://github.com/expo/expo/issues/4762
await GoogleSignIn.askForPlayServicesAsync();
const result = await GoogleSignIn.signInAsync();
if (result.type === 'success' && result.user && result.user.auth) {
const { idToken, accessToken } = result.user.auth;
await firebaseLogin(idToken || '', accessToken || '');
} else {
Sentry.captureMessage(JSON.stringify(result));
}
} else {
const androidClientId = process.env.GOOGLE_LOGIN_ANDROID_CLIENT_ID;
const iosClientId = process.env.GOOGLE_LOGIN_IOS_CLIENT_ID;
const result = await Google.logInAsync({
clientId:
Platform.OS === 'ios' ? String(iosClientId) : String(androidClientId),
iosClientId,
androidClientId,
_signInAsync = async () => {
try {
await GoogleSignIn.askForPlayServicesAsync();
const { type, user } = await GoogleSignIn.signInAsync();
console.log({ type, user });
if (type === 'success') {
this._syncUserWithStateAsync();
}
} catch ({ message }) {
console.error('login: Error:' + message);
}
}
}
clientId: Platform.select({
ios: iOSExpoClientId,
android: androidExpoClientId,
}),
});
Alert.alert('login:' + JSON.stringify(response.accessToken));
} catch ({ message }) {
Alert.alert(`Google Login Error: ${message}`);
} finally {
setSigningInGoogle(false);
}
return;
}
try {
await GoogleSignIn.askForPlayServicesAsync();
const { type, user } = await GoogleSignIn.signInAsync();
if (type === 'success') {
setGoogleUser(user);
Alert.alert('login:' + JSON.stringify(user));
onLogin();
setAuthUser({
uid: '',
displayName: '',
thumbURL: '',
photoURL: '',
statusMsg: '',
friends: [],
chatrooms: [],
signedInWith: SignInType.Google,
});
resetToMainStack();