Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_signOutAsync = async () => {
try {
// await GoogleSignIn.disconnectAsync();
await GoogleSignIn.signOutAsync();
console.log('Log out successful');
} catch ({ message }) {
console.error('Demo: Error: logout: ' + message);
} finally {
this.setState({ user: undefined });
}
}
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,
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,
scopes: ['profile', 'email'],
_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);
}
}
}
_configureAsync = async () => {
try {
await GoogleSignIn.initAsync({
isOfflineEnabled: false,
isPromptEnabled: true,
clientId:
'603386649315-vp4revvrcgrcjme51ebuhbkbspl048l9.apps.googleusercontent.com',
});
} catch ({ message }) {
console.error('Demo: Error: init: ' + message);
}
this._syncUserWithStateAsync();
}
_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();
const initAsync = async (): Promise => {
await GoogleSignIn.initAsync({
clientId: iOSClientId,
});
};
useDidMount(() => {
if (isStandaloneAndAndroid()) {
const androidClientId = process.env.GOOGLE_LOGIN_ANDROID_CLIENT_ID;
try {
GoogleSignIn.initAsync({
clientId: String(androidClientId),
});
} catch ({ message }) {
Sentry.captureMessage(JSON.stringify(message));
}
}
const checkLogin = async () => {
const login = await loggedIn();
if (login && !state.uid) {
const uid = await AsyncStorage.getItem('uid');
if (uid) {
setState(s => ({
...s,
uid,
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();
}