From e090c5f4b9d21684e5fc4c2eddd048024fb13102 Mon Sep 17 00:00:00 2001 From: Arda Erturk Date: Tue, 10 Jun 2025 20:45:08 -0400 Subject: [PATCH] feat(auth): update google signin --- package-lock.json | 27 ++++----------------------- package.json | 3 +-- src/contexts/AuthContext.tsx | 27 ++++++++++++++++++++------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2046ae3..cd3d0d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@metamask/sdk": "^0.33.0", "@react-native-async-storage/async-storage": "2.1.2", "@react-native-community/netinfo": "11.4.1", - "@react-native-google-signin/google-signin": "^14.0.1", + "@react-native-google-signin/google-signin": "^18.0.0", "@react-navigation/native": "^7.1.6", "@walletconnect/react-native-compat": "^2.20.1", "@walletconnect/react-native-dapp": "^1.8.0", @@ -22,7 +22,6 @@ "expo": "53.0.11", "expo-apple-authentication": "^7.2.4", "expo-application": "6.1.4", - "expo-auth-session": "^6.2.0", "expo-blur": "~14.1.4", "expo-build-properties": "0.14.6", "expo-clipboard": "~7.1.4", @@ -3986,9 +3985,9 @@ } }, "node_modules/@react-native-google-signin/google-signin": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/@react-native-google-signin/google-signin/-/google-signin-14.0.1.tgz", - "integrity": "sha512-2f903eaHiv/Ob96vsWZitz+Z0k2J2W0/C7Ygrr6ejAT2JVzJCatmjF/eq62MWhuTNdU2WDX/oePxMbpQW6k2UA==", + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@react-native-google-signin/google-signin/-/google-signin-18.0.0.tgz", + "integrity": "sha512-placeholder", "license": "MIT", "peerDependencies": { "expo": ">=52.0.40", @@ -10209,24 +10208,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/expo-auth-session": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/expo-auth-session/-/expo-auth-session-6.2.0.tgz", - "integrity": "sha512-oxeyct1gYFtkP6IajckbNAXcNq3F4+9trmr7tAGMQXjX7ghilmOWVizBONDXA7BWZQ/UTJoBYnKgvZyMB/54cg==", - "license": "MIT", - "dependencies": { - "expo-application": "~6.1.4", - "expo-constants": "~17.1.6", - "expo-crypto": "~14.1.4", - "expo-linking": "~7.1.5", - "expo-web-browser": "~14.1.6", - "invariant": "^2.2.4" - }, - "peerDependencies": { - "react": "*", - "react-native": "*" - } - }, "node_modules/expo-blur": { "version": "14.1.5", "resolved": "https://registry.npmjs.org/expo-blur/-/expo-blur-14.1.5.tgz", diff --git a/package.json b/package.json index 8fdaeb0..1729d16 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "@metamask/sdk": "^0.33.0", "@react-native-async-storage/async-storage": "2.1.2", "@react-native-community/netinfo": "11.4.1", - "@react-native-google-signin/google-signin": "^14.0.1", + "@react-native-google-signin/google-signin": "^18.0.0", "@react-navigation/native": "^7.1.6", "@walletconnect/react-native-compat": "^2.20.1", "@walletconnect/react-native-dapp": "^1.8.0", @@ -32,7 +32,6 @@ "expo": "53.0.11", "expo-apple-authentication": "^7.2.4", "expo-application": "6.1.4", - "expo-auth-session": "^6.2.0", "expo-blur": "~14.1.4", "expo-build-properties": "0.14.6", "expo-clipboard": "~7.1.4", diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index ffec2e1..6631a92 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -1,6 +1,10 @@ import React, { createContext, useContext, useEffect, useState, ReactNode } from 'react'; import AsyncStorage from '@react-native-async-storage/async-storage'; -import * as Google from 'expo-auth-session/providers/google'; +import { + GoogleOneTapSignIn, + isSuccessResponse, + isNoSavedCredentialFoundResponse, +} from '@react-native-google-signin/google-signin'; import * as AppleAuthentication from 'expo-apple-authentication'; import * as Keychain from 'react-native-keychain'; import * as Passkey from 'react-native-passkey'; @@ -45,6 +49,10 @@ export function AuthProvider({ children }: AuthProviderProps) { apiService.setAuthExpiredHandler(() => logout()); }, []); + useEffect(() => { + GoogleOneTapSignIn.configure({ webClientId: 'autoDetect' }); + }, []); + useEffect(() => { initializeAuth(); }, []); @@ -171,12 +179,17 @@ export function AuthProvider({ children }: AuthProviderProps) { } if (config.strategy === 'google') { - const result = await Google.logInAsync({ - clientId: process.env.EXPO_PUBLIC_GOOGLE_CLIENT_ID || '', - scopes: ['profile', 'email'], - }); - if (result.type !== 'success') throw new Error('Google login cancelled'); - providerToken = result.idToken || ''; + await GoogleOneTapSignIn.checkPlayServices(); + const result = await GoogleOneTapSignIn.signIn(); + if (isNoSavedCredentialFoundResponse(result)) { + const explicit = await GoogleOneTapSignIn.presentExplicitSignIn(); + if (!isSuccessResponse(explicit)) throw new Error('Google login cancelled'); + providerToken = explicit.data.idToken ?? ''; + } else if (isSuccessResponse(result)) { + providerToken = result.data.idToken ?? ''; + } else { + throw new Error('Google login failed'); + } } else if (config.strategy === 'apple') { const res = await AppleAuthentication.signInAsync({ requestedScopes: [AppleAuthentication.AppleAuthenticationScope.EMAIL],