@@ -13,7 +13,7 @@ import {initTracking} from 'web/lib/service/analytics'
1313import WebPush from "web/lib/service/web-push" ;
1414import AndroidPush from "web/lib/service/android-push" ;
1515import { GoogleAuthProvider , signInWithCredential } from "firebase/auth" ;
16- import { auth } from "web/lib/firebase/users" ;
16+ import { auth , GOOGLE_CLIENT_ID } from "web/lib/firebase/users" ;
1717
1818// See https://nextjs.org/docs/basic-features/font-optimization#google-fonts
1919// and if you add a font, you must add it to tailwind config as well for it to work.
@@ -67,16 +67,39 @@ function MyApp({Component, pageProps}: AppProps<PageProps>) {
6767
6868 useEffect ( ( ) => {
6969 async function oauthRedirect ( event : any ) {
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
70+ console . log ( 'Received oauthRedirect event:' , event ) ;
71+ const detail = event . data
72+ console . log ( 'OAuth data:' , detail ) ;
73+ if ( ! detail ) {
74+ console . error ( 'No detail found in event' ) ;
75+ return ;
76+ }
77+ const url = new URL ( detail ) ;
78+
79+ const code = url . searchParams . get ( 'code' ) ;
80+ if ( ! code ) {
81+ console . error ( 'No code found in URL' ) ;
82+ return ;
83+ }
84+
85+ const codeVerifier = localStorage . getItem ( 'pkce_verifier' ) ;
86+
87+ const body = new URLSearchParams ( {
88+ client_id : GOOGLE_CLIENT_ID ,
89+ code,
90+ code_verifier : codeVerifier ! ,
91+ redirect_uri : 'com.compassmeet://auth' ,
92+ grant_type : 'authorization_code' ,
93+ } ) ;
94+ console . log ( 'Body:' , body ) ;
95+ const tokenResponse = await fetch ( 'https://oauth2.googleapis.com/token' , {
96+ method : 'POST' ,
97+ headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } ,
98+ body : body ,
99+ } ) ;
100+
101+ const tokens = await tokenResponse . json ( ) ;
102+ console . log ( 'Tokens:' , tokens ) ;
80103 }
81104
82105 // Expose globally for native bridge
0 commit comments