@@ -5,8 +5,7 @@ import {getAuth, GoogleAuthProvider, signInWithPopup} from 'firebase/auth'
55
66import { safeLocalStorage } from '../util/local'
77import { app } from './init'
8- import { IS_LOCAL } from "common/envs/constants" ;
9- import { GOOGLE_CLIENT_ID } from "common/constants" ;
8+ import { GOOGLE_CLIENT_ID , REDIRECT_URI } from "common/constants" ;
109
1110dayjs . extend ( utc )
1211
@@ -73,10 +72,10 @@ async function generatePKCE() {
7372/**
7473 * Authenticates a Firebase client running a webview APK on Android with Google OAuth.
7574 *
76- * `https://accounts.google.com/o/oauth2/v2/auth?${params}` to get the code (in external browser, as google blocks it in webview)
77- * Redirects to `com.compassmeet://auth` (in webview java main activity)
78- * ' https://oauth2.googleapis .com/token' to get the ID token (in javascript app )
79- * signInWithCredential(auth, credential) to set up firebase user in client (auth.currentUser)
75+ * Calls `https://accounts.google.com/o/oauth2/v2/auth?${params}` to get the code (in external browser, as Google blocks it in webview)
76+ * Redirects to `com.compassmeet://auth` (in webview java main activity), which triggers oauthRedirect in the app (see _app.tsx)
77+ * Calls backend endpoint ` https://api.compassmeet .com/auth-google` to get the tokens from the code ('https://oauth2.googleapis.com/token' )
78+ * Uses signInWithCredential(auth, credential) to set up firebase user in the client (auth.currentUser)
8079 *
8180 * @public
8281 */
@@ -86,7 +85,7 @@ export async function webviewGoogleSignin() {
8685
8786 const params = new URLSearchParams ( {
8887 client_id : GOOGLE_CLIENT_ID ,
89- redirect_uri : `https://compassmeet.com/auth/callback` ,
88+ redirect_uri : REDIRECT_URI ,
9089 response_type : 'code' ,
9190 scope : 'openid email profile' ,
9291 code_challenge : codeChallenge ,
@@ -97,48 +96,8 @@ export async function webviewGoogleSignin() {
9796 window . open ( `https://accounts.google.com/o/oauth2/v2/auth?${ params } ` , '_system' ) ;
9897}
9998
100- // export async function googleNativeLogin() {
101- // console.log('Platform:', Capacitor.getPlatform())
102- // console.log('URL origin:', window.location.origin)
103- //
104- // await SocialLogin.initialize({
105- // google: {
106- // webClientId: '253367029065-khkj31qt22l0vc3v754h09vhpg6t33ad.apps.googleusercontent.com', // Required for Android and Web
107- // // iOSClientId: 'YOUR_IOS_CLIENT_ID', // Required for iOS
108- // // iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Required for iOS offline mode and server authorization (same as webClientId)
109- // mode: 'online', // 'online' or 'offline'
110- // }
111- // });
112- // console.log('Done initializing SocialLogin')
113- //
114- // // Run the native Google OAuth
115- // const result: any = await SocialLogin.login({provider: 'google', options: {}})
116- //
117- // console.log('result', result)
118- //
119- // // Extract the tokens from the native result
120- // const idToken = result?.result?.idToken
121- // const accessToken = result?.result?.accessToken?.token
122- //
123- // if (!idToken) {
124- // throw new Error('No idToken returned from Google login')
125- // }
126- //
127- // // Create a Firebase credential from the Google tokens
128- // const credential = GoogleAuthProvider.credential(idToken, accessToken)
129- //
130- // // Sign in with Firebase using the credential
131- // const userCredential = await signInWithCredential(auth, credential)
132- //
133- // console.log('Firebase user:', userCredential.user)
134- //
135- // return userCredential
136- // }
137-
138- // export const isRunningInAPK = () => typeof window !== 'undefined' && (window as any).IS_APK === true
139-
14099export async function firebaseLogin ( ) {
141- if ( isAndroidWebView ( ) || IS_LOCAL ) {
100+ if ( isAndroidWebView ( ) ) {
142101 console . log ( 'Running in APK' )
143102 return await webviewGoogleSignin ( )
144103 }
0 commit comments