Skip to content

Commit 6e537f4

Browse files
committed
Fix
1 parent b121d61 commit 6e537f4

File tree

2 files changed

+55
-27
lines changed

2 files changed

+55
-27
lines changed

web/pages/_app.tsx

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {initTracking} from 'web/lib/service/analytics'
1313
import WebPush from "web/lib/service/web-push";
1414
import AndroidPush from "web/lib/service/android-push";
1515
import {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

web/pages/auth/callback.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,27 @@ export default function GoogleAuthCallback() {
1010
console.log('/auth/callback code', code);
1111

1212
if (code) {
13-
const codeVerifier = localStorage.getItem('pkce_verifier');
14-
const body = new URLSearchParams({
15-
client_id: GOOGLE_CLIENT_ID,
16-
code,
17-
code_verifier: codeVerifier!,
18-
redirect_uri: 'com.compassmeet://auth',
19-
grant_type: 'authorization_code',
20-
});
21-
console.log('Body:', body);
22-
const tokenResponse = await fetch('https://oauth2.googleapis.com/token', {
23-
method: 'POST',
24-
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
25-
body: body,
26-
});
27-
const tokens = await tokenResponse.json();
28-
console.log('Tokens:', tokens);
13+
// Send code back to the native app
14+
const deepLink = `com.compassmeet://auth?code=${encodeURIComponent(code)}&state=${encodeURIComponent(state || '')}`;
15+
window.location.href = deepLink;
16+
17+
//
18+
// const codeVerifier = localStorage.getItem('pkce_verifier');
19+
// const body = new URLSearchParams({
20+
// client_id: GOOGLE_CLIENT_ID,
21+
// code,
22+
// code_verifier: codeVerifier!,
23+
// redirect_uri: 'com.compassmeet://auth',
24+
// grant_type: 'authorization_code',
25+
// });
26+
// console.log('Body:', body);
27+
// const tokenResponse = await fetch('https://oauth2.googleapis.com/token', {
28+
// method: 'POST',
29+
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
30+
// body: body,
31+
// });
32+
// const tokens = await tokenResponse.json();
33+
// console.log('Tokens:', tokens);
2934

3035
// Send code back to the native app
3136
// const deepLink = `com.compassmeet://auth?tokens=${encodeURIComponent(tokens)}}`;

0 commit comments

Comments
 (0)