@@ -12,7 +12,8 @@ import clsx from 'clsx'
1212import { initTracking } from 'web/lib/service/analytics'
1313import WebPush from "web/lib/service/web-push" ;
1414import AndroidPush from "web/lib/service/android-push" ;
15- import { GOOGLE_CLIENT_ID } from "web/lib/firebase/users" ;
15+ import { GoogleAuthProvider , signInWithCredential } from "firebase/auth" ;
16+ import { auth } from "web/lib/firebase/users" ;
1617
1718// See https://nextjs.org/docs/basic-features/font-optimization#google-fonts
1819// and if you add a font, you must add it to tailwind config as well for it to work.
@@ -66,37 +67,16 @@ function MyApp({Component, pageProps}: AppProps<PageProps>) {
6667
6768 useEffect ( ( ) => {
6869 async function oauthRedirect ( event : any ) {
69- console . log ( 'Received oauthRedirect event:' , event ) ;
70- const detail = event . data
71- console . log ( 'OAuth data:' , detail ) ;
72- if ( ! detail ) {
73- console . error ( 'No detail found in event' ) ;
74- return ;
75- }
76- const url = new URL ( detail ) ;
77-
78- const code = url . searchParams . get ( 'code' ) ;
79- if ( ! code ) {
80- console . error ( 'No code found in URL' ) ;
81- return ;
82- }
83-
84- const codeVerifier = localStorage . getItem ( 'pkce_verifier' ) ;
85-
86- const tokenResponse = await fetch ( 'https://oauth2.googleapis.com/token' , {
87- method : 'POST' ,
88- headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } ,
89- body : new URLSearchParams ( {
90- client_id : GOOGLE_CLIENT_ID ,
91- code,
92- code_verifier : codeVerifier ! ,
93- redirect_uri : 'com.compassmeet://auth' ,
94- grant_type : 'authorization_code' ,
95- } ) ,
96- } ) ;
97-
98- const tokens = await tokenResponse . json ( ) ;
99- console . log ( 'Tokens:' , tokens ) ;
70+ const { idToken, accessToken} = event
71+ // Create a Firebase credential from the Google tokens
72+ const credential = GoogleAuthProvider . credential ( idToken , accessToken )
73+
74+ // Sign in with Firebase using the credential
75+ const userCredential = await signInWithCredential ( auth , credential )
76+
77+ console . log ( 'Firebase user:' , userCredential . user )
78+
79+ return userCredential
10080 }
10181
10282 // Expose globally for native bridge
0 commit comments