Skip to content

Commit 98ab897

Browse files
committed
Clean
1 parent 870c86f commit 98ab897

File tree

5 files changed

+13
-76
lines changed

5 files changed

+13
-76
lines changed

android/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ Backend logs can be accessed from the output of `yarn prod / dev` like in the we
183183

184184
Java/Kotlin logs can be accessed via Android Studio's Logcat.
185185
```
186+
adb logcat | grep CompassApp
186187
adb logcat | grep com.compass.app
187188
adb logcat | grep Capacitor
188-
adb logcat | grep console
189189
```
190190

191191
You can also add this inside `MainActivity.java`:

backend/api/src/auth-google.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {APIError, APIHandler} from './helpers/endpoint'
2-
import {GOOGLE_CLIENT_ID} from "common/constants";
2+
import {GOOGLE_CLIENT_ID, REDIRECT_URI} from "common/constants";
33

44
export const authGoogle: APIHandler<'auth-google'> = async (
55
{code, codeVerifier},
@@ -14,7 +14,7 @@ export const authGoogle: APIHandler<'auth-google'> = async (
1414
code: code as string,
1515
code_verifier: codeVerifier as string,
1616
grant_type: 'authorization_code',
17-
redirect_uri: `https://compassmeet.com/auth/callback`,
17+
redirect_uri: REDIRECT_URI,
1818
};
1919
console.log('Body:', body)
2020
const tokenRes = await fetch('https://oauth2.googleapis.com/token', {

common/src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ export const IS_MAINTENANCE = false // set to true to enable the maintenance mod
2323
export const MIN_BIO_LENGTH = 250
2424

2525
export const WEB_GOOGLE_CLIENT_ID = '253367029065-khkj31qt22l0vc3v754h09vhpg6t33ad.apps.googleusercontent.com'
26-
export const ANDROID_GOOGLE_CLIENT_ID = '253367029065-s9sr5vqgkhc8f7p5s6ti6a4chqsrqgc4.apps.googleusercontent.com'
26+
// export const ANDROID_GOOGLE_CLIENT_ID = '253367029065-s9sr5vqgkhc8f7p5s6ti6a4chqsrqgc4.apps.googleusercontent.com'
2727
export const GOOGLE_CLIENT_ID = WEB_GOOGLE_CLIENT_ID
28+
29+
export const REDIRECT_URI = `https://compassmeet.com/auth/callback`

web/lib/firebase/users.ts

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {getAuth, GoogleAuthProvider, signInWithPopup} from 'firebase/auth'
55

66
import {safeLocalStorage} from '../util/local'
77
import {app} from './init'
8-
import {IS_LOCAL} from "common/envs/constants";
9-
import {GOOGLE_CLIENT_ID} from "common/constants";
8+
import {GOOGLE_CLIENT_ID, REDIRECT_URI} from "common/constants";
109

1110
dayjs.extend(utc)
1211

@@ -73,10 +72,10 @@ async function generatePKCE() {
7372
/**
7473
* Authenticates a Firebase client running a webview APK on Android with Google OAuth.
7574
*
76-
* `https://accounts.google.com/o/oauth2/v2/auth?${params}` to get the code (in external browser, as google blocks it in webview)
77-
* Redirects to `com.compassmeet://auth` (in webview java main activity)
78-
* 'https://oauth2.googleapis.com/token' to get the ID token (in javascript app)
79-
* signInWithCredential(auth, credential) to set up firebase user in client (auth.currentUser)
75+
* Calls `https://accounts.google.com/o/oauth2/v2/auth?${params}` to get the code (in external browser, as Google blocks it in webview)
76+
* Redirects to `com.compassmeet://auth` (in webview java main activity), which triggers oauthRedirect in the app (see _app.tsx)
77+
* Calls backend endpoint `https://api.compassmeet.com/auth-google` to get the tokens from the code ('https://oauth2.googleapis.com/token')
78+
* Uses signInWithCredential(auth, credential) to set up firebase user in the client (auth.currentUser)
8079
*
8180
* @public
8281
*/
@@ -86,7 +85,7 @@ export async function webviewGoogleSignin() {
8685

8786
const params = new URLSearchParams({
8887
client_id: GOOGLE_CLIENT_ID,
89-
redirect_uri: `https://compassmeet.com/auth/callback`,
88+
redirect_uri: REDIRECT_URI,
9089
response_type: 'code',
9190
scope: 'openid email profile',
9291
code_challenge: codeChallenge,
@@ -97,48 +96,8 @@ export async function webviewGoogleSignin() {
9796
window.open(`https://accounts.google.com/o/oauth2/v2/auth?${params}`, '_system');
9897
}
9998

100-
// export async function googleNativeLogin() {
101-
// console.log('Platform:', Capacitor.getPlatform())
102-
// console.log('URL origin:', window.location.origin)
103-
//
104-
// await SocialLogin.initialize({
105-
// google: {
106-
// webClientId: '253367029065-khkj31qt22l0vc3v754h09vhpg6t33ad.apps.googleusercontent.com', // Required for Android and Web
107-
// // iOSClientId: 'YOUR_IOS_CLIENT_ID', // Required for iOS
108-
// // iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Required for iOS offline mode and server authorization (same as webClientId)
109-
// mode: 'online', // 'online' or 'offline'
110-
// }
111-
// });
112-
// console.log('Done initializing SocialLogin')
113-
//
114-
// // Run the native Google OAuth
115-
// const result: any = await SocialLogin.login({provider: 'google', options: {}})
116-
//
117-
// console.log('result', result)
118-
//
119-
// // Extract the tokens from the native result
120-
// const idToken = result?.result?.idToken
121-
// const accessToken = result?.result?.accessToken?.token
122-
//
123-
// if (!idToken) {
124-
// throw new Error('No idToken returned from Google login')
125-
// }
126-
//
127-
// // Create a Firebase credential from the Google tokens
128-
// const credential = GoogleAuthProvider.credential(idToken, accessToken)
129-
//
130-
// // Sign in with Firebase using the credential
131-
// const userCredential = await signInWithCredential(auth, credential)
132-
//
133-
// console.log('Firebase user:', userCredential.user)
134-
//
135-
// return userCredential
136-
// }
137-
138-
// export const isRunningInAPK = () => typeof window !== 'undefined' && (window as any).IS_APK === true
139-
14099
export async function firebaseLogin() {
141-
if (isAndroidWebView() || IS_LOCAL) {
100+
if (isAndroidWebView()) {
142101
console.log('Running in APK')
143102
return await webviewGoogleSignin()
144103
}

web/pages/auth/callback.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,10 @@ export default function GoogleAuthCallback() {
66
const params = new URLSearchParams(window.location.search);
77
console.log('/auth/callback', params);
88
const code = params.get('code');
9-
// const state = params.get('state');
109

1110
if (code) {
12-
console.log('/auth/callback code', code);
1311
// Send code back to the native app
1412
window.location.href = `com.compassmeet://auth?code=${encodeURIComponent(code)}}`;
15-
16-
// const codeVerifier = localStorage.getItem('pkce_verifier');
17-
// const body = new URLSearchParams({
18-
// client_id: GOOGLE_CLIENT_ID,
19-
// code,
20-
// code_verifier: codeVerifier!,
21-
// redirect_uri: 'com.compassmeet://auth',
22-
// grant_type: 'authorization_code',
23-
// });
24-
// console.log('Body:', body);
25-
// const tokenResponse = await fetch('https://oauth2.googleapis.com/token', {
26-
// method: 'POST',
27-
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
28-
// body: body,
29-
// });
30-
// const tokens = await tokenResponse.json();
31-
// console.log('Tokens:', tokens);
32-
33-
// Send code back to the native app
34-
// const deepLink = `com.compassmeet://auth?tokens=${encodeURIComponent(tokens)}}`;
35-
// window.location.href = deepLink;
36-
3713
} else {
3814
document.body.textContent = 'Missing code in redirect.';
3915
}

0 commit comments

Comments
 (0)