From 5b1cc2befb598dda2988359a18e68bac41e117c6 Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Fri, 3 Dec 2021 17:30:22 +0200 Subject: [PATCH 01/12] Web - Firebase Google Signin and Singout --- .gitignore | 1 + template/src/app/auth-providers/Google.tsx | 8 ++++++-- template/src/app/signed-in/Settings.tsx | 2 ++ template/src/app/signed-out/SignIn.tsx | 2 +- template/src/shims/firebase-google-signin-web.ts | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 template/src/shims/firebase-google-signin-web.ts diff --git a/.gitignore b/.gitignore index dd498bd..91ceaac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ template/yarn.lock template/ios/Podfile.lock node_modules/ yarn.lock +.idea diff --git a/template/src/app/auth-providers/Google.tsx b/template/src/app/auth-providers/Google.tsx index ea67a8c..6649001 100644 --- a/template/src/app/auth-providers/Google.tsx +++ b/template/src/app/auth-providers/Google.tsx @@ -1,6 +1,6 @@ import auth from '@react-native-firebase/auth'; import {useContext, useEffect, useState} from 'react'; -import {Alert} from 'react-native'; +import {Alert, Platform} from 'react-native'; import {FirebaseError} from '@firebase/util'; import { GoogleSignin, @@ -9,6 +9,7 @@ import { import {UserContext} from '../App'; import ProviderButton from '../components/AuthProviderButton'; import {getProviderButtonTitle} from '../util/helpers'; +import {signInWithPopup} from '../../shims/firebase-google-signin-web'; const PROVIDER_ID = 'google.com'; @@ -88,7 +89,10 @@ function Google(): JSX.Element | null { } return ( - + {title} ); diff --git a/template/src/app/signed-in/Settings.tsx b/template/src/app/signed-in/Settings.tsx index bfb1239..96b254f 100644 --- a/template/src/app/signed-in/Settings.tsx +++ b/template/src/app/signed-in/Settings.tsx @@ -14,6 +14,7 @@ import { } from 'react-native-paper'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {useAppSettings} from '../AppSettings'; +import {signOutGoogle} from '../../shims/firebase-google-signin-web'; function EditProfile(): JSX.Element | null { const user = auth().currentUser; @@ -62,6 +63,7 @@ function EditProfile(): JSX.Element | null { setSigningOut(true); await GoogleSignin.signOut(); await auth().signOut(); + await signOutGoogle(); } async function handleDisplayName() { diff --git a/template/src/app/signed-out/SignIn.tsx b/template/src/app/signed-out/SignIn.tsx index 5ee940f..657ef1f 100644 --- a/template/src/app/signed-out/SignIn.tsx +++ b/template/src/app/signed-out/SignIn.tsx @@ -51,7 +51,7 @@ function SignIn() { /> {Platform.OS !== 'web' && } - {Platform.OS !== 'web' && } + {Platform.OS !== 'web' && } + await signInWithPopupFirebase(auth, provider); +export const signOutGoogle = async () => await signOutFirebase(auth); From 52f0d93213213653c344c9ea52e2b23bd729df7c Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Fri, 3 Dec 2021 18:08:04 +0200 Subject: [PATCH 02/12] Google Signout condition for web --- template/src/app/signed-in/Settings.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/template/src/app/signed-in/Settings.tsx b/template/src/app/signed-in/Settings.tsx index 96b254f..8a9b3e9 100644 --- a/template/src/app/signed-in/Settings.tsx +++ b/template/src/app/signed-in/Settings.tsx @@ -1,6 +1,6 @@ import auth from '@react-native-firebase/auth'; import {useEffect, useState} from 'react'; -import {Alert, ScrollView, StyleSheet, View} from 'react-native'; +import {Alert, Platform, ScrollView, StyleSheet, View} from 'react-native'; import {GoogleSignin} from '@react-native-google-signin/google-signin'; import { Banner, @@ -63,7 +63,9 @@ function EditProfile(): JSX.Element | null { setSigningOut(true); await GoogleSignin.signOut(); await auth().signOut(); - await signOutGoogle(); + if (Platform.OS === 'web') { + await signOutGoogle(); + } } async function handleDisplayName() { From 23c2062ac8ff9b96fc487d3eade79cf2e53835f3 Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Fri, 3 Dec 2021 18:27:09 +0200 Subject: [PATCH 03/12] Google Signout condition for web --- template/src/app/signed-in/Settings.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/template/src/app/signed-in/Settings.tsx b/template/src/app/signed-in/Settings.tsx index 8a9b3e9..37b0b45 100644 --- a/template/src/app/signed-in/Settings.tsx +++ b/template/src/app/signed-in/Settings.tsx @@ -61,10 +61,12 @@ function EditProfile(): JSX.Element | null { async function signOut() { setSigningOut(true); - await GoogleSignin.signOut(); await auth().signOut(); + if (Platform.OS === 'web') { await signOutGoogle(); + } else { + await GoogleSignin.signOut(); } } From f5559e38eb1f4ef64f7d7498ffeee4a882dfbec1 Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Fri, 3 Dec 2021 18:29:37 +0200 Subject: [PATCH 04/12] GoogleSignin.configure only for native --- template/src/app/auth-providers/Google.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/template/src/app/auth-providers/Google.tsx b/template/src/app/auth-providers/Google.tsx index 6649001..0647960 100644 --- a/template/src/app/auth-providers/Google.tsx +++ b/template/src/app/auth-providers/Google.tsx @@ -77,11 +77,13 @@ function Google(): JSX.Element | null { } useEffect(() => { - GoogleSignin.configure({ - scopes: ['profile', 'email'], - // TODO: Get your web client id from firebase console --> Project Settings --> Auth --> Google Sign-in - webClientId: require('../../config.json').webClientId, - }); + if (Platform.OS !== 'web') { + GoogleSignin.configure({ + scopes: ['profile', 'email'], + // TODO: Get your web client id from firebase console --> Project Settings --> Auth --> Google Sign-in + webClientId: require('../../config.json').webClientId, + }); + } }, []); if (isOnlyProvider) { From 03908345416e283c6dd31cce47149bd2d64e6951 Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Sat, 4 Dec 2021 13:04:57 +0200 Subject: [PATCH 05/12] Refactor - Web Google Signin using Firebase --- template/src/app/auth-providers/Google.tsx | 99 +++++++++---------- template/src/app/signed-in/Settings.tsx | 5 +- .../app/types/@react-native-firebased.d.ts | 7 ++ template/src/shims/firebase-auth-web.ts | 19 ++++ .../src/shims/firebase-google-signin-web.ts | 16 --- 5 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 template/src/app/types/@react-native-firebased.d.ts delete mode 100644 template/src/shims/firebase-google-signin-web.ts diff --git a/template/src/app/auth-providers/Google.tsx b/template/src/app/auth-providers/Google.tsx index 0647960..e900bf3 100644 --- a/template/src/app/auth-providers/Google.tsx +++ b/template/src/app/auth-providers/Google.tsx @@ -1,4 +1,4 @@ -import auth from '@react-native-firebase/auth'; +import auth, {googleWebSignInWithPopup} from '@react-native-firebase/auth'; import {useContext, useEffect, useState} from 'react'; import {Alert, Platform} from 'react-native'; import {FirebaseError} from '@firebase/util'; @@ -9,7 +9,6 @@ import { import {UserContext} from '../App'; import ProviderButton from '../components/AuthProviderButton'; import {getProviderButtonTitle} from '../util/helpers'; -import {signInWithPopup} from '../../shims/firebase-google-signin-web'; const PROVIDER_ID = 'google.com'; @@ -24,53 +23,56 @@ function Google(): JSX.Element | null { async function handleGoogle() { if (!loading) { setLoading(true); + if (Platform.OS === 'web') { + await googleWebSignInWithPopup(); + } else { + try { + await GoogleSignin.hasPlayServices(); - try { - await GoogleSignin.hasPlayServices(); - - if (variant === 'UNLINK' && user) { - await user.unlink(PROVIDER_ID); - await user.reload(); - } else { - await GoogleSignin.signIn(); - const {accessToken, idToken} = await GoogleSignin.getTokens(); - const credential = auth.GoogleAuthProvider.credential( - idToken, - accessToken, - ); - - if (variant === 'LINK' && user) { - await user.linkWithCredential(credential); + if (variant === 'UNLINK' && user) { + await user.unlink(PROVIDER_ID); await user.reload(); - } else if (variant === 'SIGN_IN') { - await auth().signInWithCredential(credential); - } - } - } catch (e) { - setLoading(false); - const error = e as FirebaseError; - switch (error.code) { - case statusCodes.SIGN_IN_CANCELLED: - case '-1': - return Alert.alert('Google Auth Canceled'); - case statusCodes.IN_PROGRESS: - return Alert.alert('Google Auth Already In Progress'); - case statusCodes.PLAY_SERVICES_NOT_AVAILABLE: - return Alert.alert('Google Auth Requires Play Services'); - default: - switch (error.message) { - case 'DEVELOPER_ERROR': - console.info( - 'Developer error during Google Auth, check: ' + - 'https://github.com/react-native-community/react-native-google-signin/blob/f21dd95a090f4f529748473e20515d6fc66db6bb/example/README.md#developer_error-or-code-10-on-android', - ); - return Alert.alert( - 'Google Auth Error', - 'Google Auth has not been configured correctly for this app by the developer. More info is available in the console output.', - ); - default: - return Alert.alert('Google Auth Error', error.message); + } else { + await GoogleSignin.signIn(); + const {accessToken, idToken} = await GoogleSignin.getTokens(); + const credential = auth.GoogleAuthProvider.credential( + idToken, + accessToken, + ); + + if (variant === 'LINK' && user) { + await user.linkWithCredential(credential); + await user.reload(); + } else if (variant === 'SIGN_IN') { + await auth().signInWithCredential(credential); } + } + } catch (e) { + setLoading(false); + const error = e as FirebaseError; + switch (error.code) { + case statusCodes.SIGN_IN_CANCELLED: + case '-1': + return Alert.alert('Google Auth Canceled'); + case statusCodes.IN_PROGRESS: + return Alert.alert('Google Auth Already In Progress'); + case statusCodes.PLAY_SERVICES_NOT_AVAILABLE: + return Alert.alert('Google Auth Requires Play Services'); + default: + switch (error.message) { + case 'DEVELOPER_ERROR': + console.info( + 'Developer error during Google Auth, check: ' + + 'https://github.com/react-native-community/react-native-google-signin/blob/f21dd95a090f4f529748473e20515d6fc66db6bb/example/README.md#developer_error-or-code-10-on-android', + ); + return Alert.alert( + 'Google Auth Error', + 'Google Auth has not been configured correctly for this app by the developer. More info is available in the console output.', + ); + default: + return Alert.alert('Google Auth Error', error.message); + } + } } } } @@ -91,10 +93,7 @@ function Google(): JSX.Element | null { } return ( - + {title} ); diff --git a/template/src/app/signed-in/Settings.tsx b/template/src/app/signed-in/Settings.tsx index 37b0b45..850e935 100644 --- a/template/src/app/signed-in/Settings.tsx +++ b/template/src/app/signed-in/Settings.tsx @@ -1,4 +1,4 @@ -import auth from '@react-native-firebase/auth'; +import auth, {googleWebSignOut} from '@react-native-firebase/auth'; import {useEffect, useState} from 'react'; import {Alert, Platform, ScrollView, StyleSheet, View} from 'react-native'; import {GoogleSignin} from '@react-native-google-signin/google-signin'; @@ -14,7 +14,6 @@ import { } from 'react-native-paper'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {useAppSettings} from '../AppSettings'; -import {signOutGoogle} from '../../shims/firebase-google-signin-web'; function EditProfile(): JSX.Element | null { const user = auth().currentUser; @@ -64,7 +63,7 @@ function EditProfile(): JSX.Element | null { await auth().signOut(); if (Platform.OS === 'web') { - await signOutGoogle(); + await googleWebSignOut(); } else { await GoogleSignin.signOut(); } diff --git a/template/src/app/types/@react-native-firebased.d.ts b/template/src/app/types/@react-native-firebased.d.ts new file mode 100644 index 0000000..502b4a0 --- /dev/null +++ b/template/src/app/types/@react-native-firebased.d.ts @@ -0,0 +1,7 @@ +import {UserCredential} from 'firebase/auth'; + +declare module '@react-native-firebase/auth' { + export const googleWebSignInWithPopup: () => Promise; + export const googleWebSignInWithRedirect: () => Promise; + export const googleWebSignOut: () => Promise; +} diff --git a/template/src/shims/firebase-auth-web.ts b/template/src/shims/firebase-auth-web.ts index 6e4e6da..380613f 100644 --- a/template/src/shims/firebase-auth-web.ts +++ b/template/src/shims/firebase-auth-web.ts @@ -1,8 +1,27 @@ import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; +import { + getAuth, + GoogleAuthProvider, + signInWithPopup, + signInWithRedirect, + signOut, +} from 'firebase/auth'; + import initializeApp from './firebase-init'; initializeApp(); const auth = firebase.auth; +const firebaseAuth = getAuth(); + +const provider = new GoogleAuthProvider(); +provider.setCustomParameters({prompt: 'select_account'}); + +export const googleWebSignInWithPopup = async () => + await signInWithPopup(firebaseAuth, provider); +export const googleWebSignInWithRedirect = async () => + await signInWithRedirect(firebaseAuth, provider); +export const googleWebSignOut = async () => await signOut(firebaseAuth); + export default auth; diff --git a/template/src/shims/firebase-google-signin-web.ts b/template/src/shims/firebase-google-signin-web.ts deleted file mode 100644 index ca2fa33..0000000 --- a/template/src/shims/firebase-google-signin-web.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { - getAuth, - GoogleAuthProvider, - signInWithPopup as signInWithPopupFirebase, - signOut as signOutFirebase, -} from 'firebase/auth'; - -import initializeApp from './firebase-init'; -initializeApp(); - -const provider = new GoogleAuthProvider(); -provider.setCustomParameters({prompt: 'select_account'}); -const auth = getAuth(); -export const signInWithPopup = async () => - await signInWithPopupFirebase(auth, provider); -export const signOutGoogle = async () => await signOutFirebase(auth); From 46c9ce0738ff0fd4fa436550522ebb68d38f64bc Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Sat, 4 Dec 2021 13:13:24 +0200 Subject: [PATCH 06/12] Refactor - Web Google Signin using Firebase (2) --- template/src/shims/firebase-auth-web.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/template/src/shims/firebase-auth-web.ts b/template/src/shims/firebase-auth-web.ts index 380613f..dc855e4 100644 --- a/template/src/shims/firebase-auth-web.ts +++ b/template/src/shims/firebase-auth-web.ts @@ -2,7 +2,6 @@ import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; import { - getAuth, GoogleAuthProvider, signInWithPopup, signInWithRedirect, @@ -13,15 +12,14 @@ import initializeApp from './firebase-init'; initializeApp(); const auth = firebase.auth; -const firebaseAuth = getAuth(); const provider = new GoogleAuthProvider(); provider.setCustomParameters({prompt: 'select_account'}); export const googleWebSignInWithPopup = async () => - await signInWithPopup(firebaseAuth, provider); + await signInWithPopup(auth(), provider); export const googleWebSignInWithRedirect = async () => - await signInWithRedirect(firebaseAuth, provider); -export const googleWebSignOut = async () => await signOut(firebaseAuth); + await signInWithRedirect(auth(), provider); +export const googleWebSignOut = async () => await signOut(auth()); export default auth; From 3a2ec7668ff1562755b37fd645540f91ddf850e2 Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Sat, 4 Dec 2021 13:37:01 +0200 Subject: [PATCH 07/12] Web - Google Sign In with Redirect for mobile --- template/package.json | 1 + template/src/app/auth-providers/Google.tsx | 4 ++-- template/src/app/types/@react-native-firebased.d.ts | 3 +-- template/src/shims/firebase-auth-web.ts | 11 +++++++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/template/package.json b/template/package.json index a3d3aec..65809ac 100644 --- a/template/package.json +++ b/template/package.json @@ -37,6 +37,7 @@ "i18n-js": "^3.8.0", "libphonenumber-js": "^1.9.43", "react": "^17.0.2", + "react-device-detect": "^2.1.2", "react-dom": "^17.0.2", "react-native": "^0.66.3", "react-native-country-picker-modal": "^2.0.0", diff --git a/template/src/app/auth-providers/Google.tsx b/template/src/app/auth-providers/Google.tsx index e900bf3..5f3208b 100644 --- a/template/src/app/auth-providers/Google.tsx +++ b/template/src/app/auth-providers/Google.tsx @@ -1,4 +1,4 @@ -import auth, {googleWebSignInWithPopup} from '@react-native-firebase/auth'; +import auth, {googleWebSignIn} from '@react-native-firebase/auth'; import {useContext, useEffect, useState} from 'react'; import {Alert, Platform} from 'react-native'; import {FirebaseError} from '@firebase/util'; @@ -24,7 +24,7 @@ function Google(): JSX.Element | null { if (!loading) { setLoading(true); if (Platform.OS === 'web') { - await googleWebSignInWithPopup(); + await googleWebSignIn(); } else { try { await GoogleSignin.hasPlayServices(); diff --git a/template/src/app/types/@react-native-firebased.d.ts b/template/src/app/types/@react-native-firebased.d.ts index 502b4a0..2db5b3b 100644 --- a/template/src/app/types/@react-native-firebased.d.ts +++ b/template/src/app/types/@react-native-firebased.d.ts @@ -1,7 +1,6 @@ import {UserCredential} from 'firebase/auth'; declare module '@react-native-firebase/auth' { - export const googleWebSignInWithPopup: () => Promise; - export const googleWebSignInWithRedirect: () => Promise; + export const googleWebSignIn: () => Promise; export const googleWebSignOut: () => Promise; } diff --git a/template/src/shims/firebase-auth-web.ts b/template/src/shims/firebase-auth-web.ts index dc855e4..126e463 100644 --- a/template/src/shims/firebase-auth-web.ts +++ b/template/src/shims/firebase-auth-web.ts @@ -1,5 +1,6 @@ import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; +import {isMobile} from 'react-device-detect'; import { GoogleAuthProvider, @@ -16,10 +17,16 @@ const auth = firebase.auth; const provider = new GoogleAuthProvider(); provider.setCustomParameters({prompt: 'select_account'}); -export const googleWebSignInWithPopup = async () => +const googleWebSignInWithPopup = async () => await signInWithPopup(auth(), provider); -export const googleWebSignInWithRedirect = async () => +const googleWebSignInWithRedirect = async () => await signInWithRedirect(auth(), provider); + +export const googleWebSignIn = async () => + isMobile + ? await googleWebSignInWithRedirect() + : await googleWebSignInWithPopup(); + export const googleWebSignOut = async () => await signOut(auth()); export default auth; From e185d0f965f4cd158c342610a88ecfaa8d3850b6 Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Sat, 4 Dec 2021 14:41:23 +0200 Subject: [PATCH 08/12] fix - sign out all providers before signing out auth() --- template/src/app/signed-in/Settings.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/template/src/app/signed-in/Settings.tsx b/template/src/app/signed-in/Settings.tsx index 850e935..d0d69a1 100644 --- a/template/src/app/signed-in/Settings.tsx +++ b/template/src/app/signed-in/Settings.tsx @@ -60,13 +60,14 @@ function EditProfile(): JSX.Element | null { async function signOut() { setSigningOut(true); - await auth().signOut(); if (Platform.OS === 'web') { await googleWebSignOut(); } else { await GoogleSignin.signOut(); } + + await auth().signOut(); } async function handleDisplayName() { From d307e3be90d0cfebb319ae850893eacf89738642 Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Sat, 4 Dec 2021 14:46:21 +0200 Subject: [PATCH 09/12] move types folder to src and fixed ypo in file name (types/@react-native-firebase.d.ts) --- .../@react-native-firebase.d.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename template/src/{app/types/@react-native-firebased.d.ts => types/@react-native-firebase.d.ts} (100%) diff --git a/template/src/app/types/@react-native-firebased.d.ts b/template/src/types/@react-native-firebase.d.ts similarity index 100% rename from template/src/app/types/@react-native-firebased.d.ts rename to template/src/types/@react-native-firebase.d.ts From 3df29ce07ef0ce1ae4acdd05f1b577f720c7059c Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Sat, 4 Dec 2021 15:41:16 +0200 Subject: [PATCH 10/12] move types/@react-native-firebase.d.ts to react-app-env.d.ts --- template/src/react-app-env.d.ts | 6 ++++++ template/src/types/@react-native-firebase.d.ts | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 template/src/types/@react-native-firebase.d.ts diff --git a/template/src/react-app-env.d.ts b/template/src/react-app-env.d.ts index 6431bc5..fc8b926 100644 --- a/template/src/react-app-env.d.ts +++ b/template/src/react-app-env.d.ts @@ -1 +1,7 @@ /// +import {UserCredential} from 'firebase/auth'; + +declare module '@react-native-firebase/auth' { + export const googleWebSignIn: () => Promise; + export const googleWebSignOut: () => Promise; +} diff --git a/template/src/types/@react-native-firebase.d.ts b/template/src/types/@react-native-firebase.d.ts deleted file mode 100644 index 2db5b3b..0000000 --- a/template/src/types/@react-native-firebase.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import {UserCredential} from 'firebase/auth'; - -declare module '@react-native-firebase/auth' { - export const googleWebSignIn: () => Promise; - export const googleWebSignOut: () => Promise; -} From aabddb2dae5feea7b3ecb1863829805f4c83f2fb Mon Sep 17 00:00:00 2001 From: Notorious112 Date: Sun, 5 Dec 2021 22:20:38 +0200 Subject: [PATCH 11/12] Resolve conflicts --- template/src/app/auth-providers/Google.tsx | 63 +++++++++++----------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/template/src/app/auth-providers/Google.tsx b/template/src/app/auth-providers/Google.tsx index 8f92d1b..401df75 100644 --- a/template/src/app/auth-providers/Google.tsx +++ b/template/src/app/auth-providers/Google.tsx @@ -40,38 +40,39 @@ function Google(): JSX.Element | null { accessToken, ); - if (variant === 'LINK' && user) { - await user.linkWithCredential(credential); - await user.reload(); - } else if (variant === 'SIGN_IN') { - await auth().signInWithCredential(credential); - } - } - } catch (e) { - setLoading(false); - const error = e as FirebaseError; - switch (error.code) { - case statusCodes.SIGN_IN_CANCELLED: - case '-1': - return Alert.alert('Google Auth Canceled'); - case statusCodes.IN_PROGRESS: - return Alert.alert('Google Auth Already In Progress'); - case statusCodes.PLAY_SERVICES_NOT_AVAILABLE: - return Alert.alert('Google Auth Requires Play Services'); - default: - switch (error.message) { - case 'DEVELOPER_ERROR': - console.info( - 'Developer error during Google Auth, check: ' + - 'https://github.com/react-native-google-signin/google-signin/blob/f21dd95a090f4f529748473e20515d6fc66db6bb/example/README.md#developer_error-or-code-10-on-android', - ); - return Alert.alert( - 'Google Auth Error', - 'Google Auth has not been configured correctly for this app by the developer. More info is available in the console output.', - ); - default: - return Alert.alert('Google Auth Error', error.message); + if (variant === 'LINK' && user) { + await user.linkWithCredential(credential); + await user.reload(); + } else if (variant === 'SIGN_IN') { + await auth().signInWithCredential(credential); } + } + } catch (e) { + setLoading(false); + const error = e as FirebaseError; + switch (error.code) { + case statusCodes.SIGN_IN_CANCELLED: + case '-1': + return Alert.alert('Google Auth Canceled'); + case statusCodes.IN_PROGRESS: + return Alert.alert('Google Auth Already In Progress'); + case statusCodes.PLAY_SERVICES_NOT_AVAILABLE: + return Alert.alert('Google Auth Requires Play Services'); + default: + switch (error.message) { + case 'DEVELOPER_ERROR': + console.info( + 'Developer error during Google Auth, check: ' + + 'https://github.com/react-native-google-signin/google-signin/blob/f21dd95a090f4f529748473e20515d6fc66db6bb/example/README.md#developer_error-or-code-10-on-android', + ); + return Alert.alert( + 'Google Auth Error', + 'Google Auth has not been configured correctly for this app by the developer. More info is available in the console output.', + ); + default: + return Alert.alert('Google Auth Error', error.message); + } + } } } } From 5b0337c284bb279a9ad82fc0b8aaddc3bc2e3587 Mon Sep 17 00:00:00 2001 From: criszz77 Date: Fri, 24 Dec 2021 15:26:25 +0200 Subject: [PATCH 12/12] Resolve conflicts --- template/src/app/signed-in/Settings.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/src/app/signed-in/Settings.tsx b/template/src/app/signed-in/Settings.tsx index 6df6820..768620c 100644 --- a/template/src/app/signed-in/Settings.tsx +++ b/template/src/app/signed-in/Settings.tsx @@ -1,5 +1,5 @@ import {useEffect, useState} from 'react'; -import {ScrollView, StyleSheet, View} from 'react-native'; +import {Platform, ScrollView, StyleSheet, View} from 'react-native'; import auth, {googleWebSignOut} from '@react-native-firebase/auth'; import {GoogleSignin} from '@react-native-google-signin/google-signin'; import {