Skip to content

Commit 2c4ce6c

Browse files
committed
Add isAndroidWebView
1 parent f9ccd36 commit 2c4ce6c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

web/lib/firebase/users.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {type User} from 'common/user'
22
import dayjs from 'dayjs'
33
import utc from 'dayjs/plugin/utc'
4-
import {getAuth, GoogleAuthProvider, OAuthProvider, signInWithCredential, signInWithPopup,} from 'firebase/auth'
4+
import {getAuth, GoogleAuthProvider, OAuthProvider, signInWithCredential, signInWithPopup, signInWithRedirect} from 'firebase/auth'
55

66
import {safeLocalStorage} from '../util/local'
77
import {app} from './init'
@@ -45,6 +45,16 @@ export function writeReferralInfo(
4545
}
4646
}
4747

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+
4858

4959
export async function googleNativeLogin() {
5060
await SocialLogin.initialize({
@@ -87,9 +97,10 @@ export async function googleNativeLogin() {
8797
export const isRunningInAPK = () => typeof window !== 'undefined' && (window as any).IS_APK === true
8898

8999
export async function firebaseLogin() {
90-
if (isRunningInAPK()) {
100+
if (isAndroidWebView()) {
91101
console.log('Running in APK')
92102
return await googleNativeLogin()
103+
// return await signInWithRedirect(auth, new GoogleAuthProvider())
93104
}
94105
console.log('Running in web')
95106
const provider = new GoogleAuthProvider()

web/pages/signin.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function RegisterComponent() {
6565
setError(null)
6666
try {
6767
const creds = await firebaseLogin();
68+
console.debug('creds', creds)
6869
if (creds) {
6970
setIsLoading(true)
7071
setIsLoadingGoogle(true);

0 commit comments

Comments
 (0)