@@ -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 , isAndroidWebView } from "web/lib/firebase/users" ;
15+ import { GOOGLE_CLIENT_ID } 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.
@@ -33,6 +33,40 @@ const logoFont = Major_Mono_Display({
3333// subsets: ['latin'],
3434// })
3535
36+ async function oauthRedirect ( event : any ) {
37+ console . log ( 'Received oauthRedirect event' ) ;
38+ console . log ( 'Received oauthRedirect event:' , event . detail ) ;
39+ const detail = typeof event . detail === 'string' ? JSON . parse ( event . detail ) : event . detail
40+ console . log ( 'OAuth data:' , detail ) ;
41+ const url = new URL ( detail ) ;
42+
43+ const code = url . searchParams . get ( 'code' ) ;
44+ if ( ! code ) {
45+ console . error ( 'No code found in URL' ) ;
46+ return ;
47+ }
48+
49+ const codeVerifier = localStorage . getItem ( 'pkce_verifier' ) ;
50+
51+ const tokenResponse = await fetch ( 'https://oauth2.googleapis.com/token' , {
52+ method : 'POST' ,
53+ headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } ,
54+ body : new URLSearchParams ( {
55+ client_id : GOOGLE_CLIENT_ID ,
56+ code,
57+ code_verifier : codeVerifier ! ,
58+ redirect_uri : 'com.compassmeet://auth' ,
59+ grant_type : 'authorization_code' ,
60+ } ) ,
61+ } ) ;
62+
63+ const tokens = await tokenResponse . json ( ) ;
64+ console . log ( 'Tokens:' , tokens ) ;
65+ }
66+
67+ // Expose globally for native bridge
68+ ( window as any ) . oauthRedirect = oauthRedirect ;
69+
3670function printBuildInfo ( ) {
3771 // These are undefined if e.g. dev server
3872 if ( process . env . NEXT_PUBLIC_VERCEL_ENV ) {
@@ -64,43 +98,6 @@ function MyApp({Component, pageProps}: AppProps<PageProps>) {
6498 }
6599 } , [ ] )
66100
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' ) ;
73- console . log ( 'Received oauthRedirect event:' , event . detail ) ;
74- const detail = typeof event . detail === 'string' ? JSON . parse ( event . detail ) : event . detail
75- console . log ( 'OAuth data:' , detail ) ;
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 ) ;
100- } ) ;
101- }
102- } , [ ] )
103-
104101 const title = 'Compass'
105102 const description = 'The platform for intentional connections'
106103
0 commit comments