@@ -33,40 +33,6 @@ 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-
7036function printBuildInfo ( ) {
7137 // These are undefined if e.g. dev server
7238 if ( process . env . NEXT_PUBLIC_VERCEL_ENV ) {
@@ -98,6 +64,42 @@ function MyApp({Component, pageProps}: AppProps<PageProps>) {
9864 }
9965 } , [ ] )
10066
67+ useEffect ( ( ) => {
68+ async function oauthRedirect ( event : any ) {
69+ console . log ( 'Received oauthRedirect event' ) ;
70+ console . log ( 'Received oauthRedirect event:' , event . detail ) ;
71+ const detail = typeof event . detail === 'string' ? JSON . parse ( event . detail ) : event . detail
72+ console . log ( 'OAuth data:' , detail ) ;
73+ const url = new URL ( 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+ }
98+
99+ // Expose globally for native bridge
100+ ( window as any ) . oauthRedirect = oauthRedirect ;
101+ } , [ ] ) ;
102+
101103 const title = 'Compass'
102104 const description = 'The platform for intentional connections'
103105
0 commit comments