@@ -12,7 +12,7 @@ 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 { GOOGLE_CLIENT_ID , isAndroidWebView } from "web/lib/firebase/users" ;
1616
1717// See https://nextjs.org/docs/basic-features/font-optimization#google-fonts
1818// and if you add a font, you must add it to tailwind config as well for it to work.
@@ -64,33 +64,39 @@ function MyApp({Component, pageProps}: AppProps<PageProps>) {
6464 }
6565 } , [ ] )
6666
67- window . addEventListener ( 'oauthRedirect' , async ( event : any ) => {
68- console . log ( 'Received oauthRedirect event:' , event . detail ) ;
69- const url = new URL ( event . detail ) ;
70-
71- const code = url . searchParams . get ( 'code' ) ;
72- if ( ! code ) {
73- console . error ( 'No code found in URL' ) ;
74- return ;
67+ useEffect ( ( ) => {
68+ if ( isAndroidWebView ( ) ) {
69+ console . log ( 'Registering OAuth redirect listener for Android WebView' )
70+
71+ window . addEventListener ( 'oauthRedirect' , async ( event : any ) => {
72+ console . log ( 'Received oauthRedirect event:' , event . detail ) ;
73+ const url = new URL ( event . detail ) ;
74+
75+ const code = url . searchParams . get ( 'code' ) ;
76+ if ( ! code ) {
77+ console . error ( 'No code found in URL' ) ;
78+ return ;
79+ }
80+
81+ const codeVerifier = localStorage . getItem ( 'pkce_verifier' ) ;
82+
83+ const tokenResponse = await fetch ( 'https://oauth2.googleapis.com/token' , {
84+ method : 'POST' ,
85+ headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } ,
86+ body : new URLSearchParams ( {
87+ client_id : GOOGLE_CLIENT_ID ,
88+ code,
89+ code_verifier : codeVerifier ! ,
90+ redirect_uri : 'com.compassmeet:/auth' ,
91+ grant_type : 'authorization_code' ,
92+ } ) ,
93+ } ) ;
94+
95+ const tokens = await tokenResponse . json ( ) ;
96+ console . log ( 'Tokens:' , tokens ) ;
97+ } ) ;
7598 }
76-
77- const codeVerifier = localStorage . getItem ( 'pkce_verifier' ) ;
78-
79- const tokenResponse = await fetch ( 'https://oauth2.googleapis.com/token' , {
80- method : 'POST' ,
81- headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } ,
82- body : new URLSearchParams ( {
83- client_id : GOOGLE_CLIENT_ID ,
84- code,
85- code_verifier : codeVerifier ! ,
86- redirect_uri : 'com.compassmeet:/auth' ,
87- grant_type : 'authorization_code' ,
88- } ) ,
89- } ) ;
90-
91- const tokens = await tokenResponse . json ( ) ;
92- console . log ( 'Tokens:' , tokens ) ;
93- } ) ;
99+ } , [ ] )
94100
95101 const title = 'Compass'
96102 const description = 'The platform for intentional connections'
0 commit comments