|
1 | 1 | import {type User} from 'common/user' |
2 | 2 | import dayjs from 'dayjs' |
3 | 3 | import utc from 'dayjs/plugin/utc' |
4 | | -import {getAuth, GoogleAuthProvider, OAuthProvider, signInWithCredential, signInWithPopup, signInWithRedirect} from 'firebase/auth' |
| 4 | +import {getAuth, GoogleAuthProvider, OAuthProvider, signInWithPopup} from 'firebase/auth' |
5 | 5 |
|
6 | 6 | import {safeLocalStorage} from '../util/local' |
7 | 7 | import {app} from './init' |
8 | | -import {SocialLogin} from "@capgo/capacitor-social-login"; |
9 | | -import {Capacitor} from "@capacitor/core"; |
10 | 8 |
|
11 | 9 | dayjs.extend(utc) |
12 | 10 |
|
@@ -45,63 +43,63 @@ export function writeReferralInfo( |
45 | 43 | } |
46 | 44 | } |
47 | 45 |
|
48 | | -export function isAndroidWebView() { |
49 | | - try { |
50 | | - // Detect if Android bridge exists |
51 | | - return typeof (window as any).AndroidBridge?.isNativeApp === 'function'; |
52 | | - } catch { |
53 | | - return false; |
54 | | - } |
55 | | -} |
56 | | - |
57 | | - |
58 | | -export async function googleNativeLogin() { |
59 | | - console.log('Platform:', Capacitor.getPlatform()) |
60 | | - console.log('URL origin:', window.location.origin) |
61 | | - |
62 | | - await SocialLogin.initialize({ |
63 | | - google: { |
64 | | - webClientId: '253367029065-khkj31qt22l0vc3v754h09vhpg6t33ad.apps.googleusercontent.com', // Required for Android and Web |
65 | | - // iOSClientId: 'YOUR_IOS_CLIENT_ID', // Required for iOS |
66 | | - // iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Required for iOS offline mode and server authorization (same as webClientId) |
67 | | - mode: 'online', // 'online' or 'offline' |
68 | | - } |
69 | | - }); |
70 | | - console.log('Done initializing SocialLogin') |
71 | | - |
72 | | - // Run the native Google OAuth |
73 | | - const result: any = await SocialLogin.login({provider: 'google', options: {}}) |
74 | | - |
75 | | - console.log('result', result) |
76 | | - |
77 | | - // Extract the tokens from the native result |
78 | | - const idToken = result?.result?.idToken |
79 | | - const accessToken = result?.result?.accessToken?.token |
80 | | - |
81 | | - if (!idToken) { |
82 | | - throw new Error('No idToken returned from Google login') |
83 | | - } |
84 | | - |
85 | | - // Create a Firebase credential from the Google tokens |
86 | | - const credential = GoogleAuthProvider.credential(idToken, accessToken) |
87 | | - |
88 | | - // Sign in with Firebase using the credential |
89 | | - const userCredential = await signInWithCredential(auth, credential) |
90 | | - |
91 | | - console.log('Firebase user:', userCredential.user) |
92 | | - |
93 | | - return userCredential |
94 | | -} |
95 | | - |
96 | | -export const isRunningInAPK = () => typeof window !== 'undefined' && (window as any).IS_APK === true |
| 46 | +// export function isAndroidWebView() { |
| 47 | +// try { |
| 48 | +// // Detect if Android bridge exists |
| 49 | +// return typeof (window as any).AndroidBridge?.isNativeApp === 'function'; |
| 50 | +// } catch { |
| 51 | +// return false; |
| 52 | +// } |
| 53 | +// } |
| 54 | + |
| 55 | + |
| 56 | +// export async function googleNativeLogin() { |
| 57 | +// console.log('Platform:', Capacitor.getPlatform()) |
| 58 | +// console.log('URL origin:', window.location.origin) |
| 59 | +// |
| 60 | +// await SocialLogin.initialize({ |
| 61 | +// google: { |
| 62 | +// webClientId: '253367029065-khkj31qt22l0vc3v754h09vhpg6t33ad.apps.googleusercontent.com', // Required for Android and Web |
| 63 | +// // iOSClientId: 'YOUR_IOS_CLIENT_ID', // Required for iOS |
| 64 | +// // iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Required for iOS offline mode and server authorization (same as webClientId) |
| 65 | +// mode: 'online', // 'online' or 'offline' |
| 66 | +// } |
| 67 | +// }); |
| 68 | +// console.log('Done initializing SocialLogin') |
| 69 | +// |
| 70 | +// // Run the native Google OAuth |
| 71 | +// const result: any = await SocialLogin.login({provider: 'google', options: {}}) |
| 72 | +// |
| 73 | +// console.log('result', result) |
| 74 | +// |
| 75 | +// // Extract the tokens from the native result |
| 76 | +// const idToken = result?.result?.idToken |
| 77 | +// const accessToken = result?.result?.accessToken?.token |
| 78 | +// |
| 79 | +// if (!idToken) { |
| 80 | +// throw new Error('No idToken returned from Google login') |
| 81 | +// } |
| 82 | +// |
| 83 | +// // Create a Firebase credential from the Google tokens |
| 84 | +// const credential = GoogleAuthProvider.credential(idToken, accessToken) |
| 85 | +// |
| 86 | +// // Sign in with Firebase using the credential |
| 87 | +// const userCredential = await signInWithCredential(auth, credential) |
| 88 | +// |
| 89 | +// console.log('Firebase user:', userCredential.user) |
| 90 | +// |
| 91 | +// return userCredential |
| 92 | +// } |
| 93 | + |
| 94 | +// export const isRunningInAPK = () => typeof window !== 'undefined' && (window as any).IS_APK === true |
97 | 95 |
|
98 | 96 | export async function firebaseLogin() { |
99 | | - if (isAndroidWebView()) { |
100 | | - console.log('Running in APK') |
101 | | - return await googleNativeLogin() |
102 | | - // return await signInWithRedirect(auth, new GoogleAuthProvider()) |
103 | | - } |
104 | | - console.log('Running in web') |
| 97 | + // if (isAndroidWebView()) { |
| 98 | + // console.log('Running in APK') |
| 99 | + // return await googleNativeLogin() |
| 100 | + // return await signInWithRedirect(auth, new GoogleAuthProvider()) |
| 101 | + // } |
| 102 | + // console.log('Running in web') |
105 | 103 | const provider = new GoogleAuthProvider() |
106 | 104 | return signInWithPopup(auth, provider).then(async (result) => { |
107 | 105 | return result |
|
0 commit comments