feat(stage-pocket,stage-server): support Android deep link for official server login (#1786)
This commit is contained in:
@@ -66,7 +66,7 @@ signIn:
|
||||
footer:
|
||||
prefix: Al continuar, aceptas nuestros
|
||||
terms: Términos
|
||||
and: "y"
|
||||
and: 'y'
|
||||
privacy: Política de Privacidad
|
||||
verifyEmail:
|
||||
title:
|
||||
|
||||
@@ -1,5 +1,53 @@
|
||||
// Centralized OIDC client configuration for the web platform.
|
||||
// Electron and Pocket have their own configs due to different client IDs and redirect strategies.
|
||||
const FALLBACK = 'http://localhost'
|
||||
|
||||
export const OIDC_CLIENT_ID = import.meta.env.VITE_OIDC_CLIENT_ID || 'airi-stage-web'
|
||||
export const OIDC_REDIRECT_URI = `${globalThis.location?.origin ?? 'http://localhost'}/auth/callback`
|
||||
/**
|
||||
* Safely retrieves environment status without crashing in non-browser runtimes.
|
||||
*/
|
||||
function getEnvStatus() {
|
||||
// If not in a browser environment, return default values immediately
|
||||
if (typeof window === 'undefined') {
|
||||
return { isAndroidNative: false, isNative: false }
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const capacitor = window.Capacitor
|
||||
const isAndroidNative = !!(capacitor?.getPlatform?.() === 'android')
|
||||
const isNative = !!capacitor || isAndroidNative
|
||||
|
||||
return { isAndroidNative, isNative }
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the redirect origin based on environment and configuration.
|
||||
*/
|
||||
function getRedirectOrigin() {
|
||||
// 1. Priority: Use environment variable if it exists
|
||||
if (import.meta.env.VITE_OIDC_REDIRECT_URI) {
|
||||
return import.meta.env.VITE_OIDC_REDIRECT_URI
|
||||
}
|
||||
|
||||
const { isAndroidNative } = getEnvStatus()
|
||||
|
||||
// 2. Handle Android Native (Capacitor) environment
|
||||
if (isAndroidNative) {
|
||||
return 'ai.moeru.airi_pocket://links'
|
||||
}
|
||||
|
||||
// 3. Handle standard browser environment
|
||||
if (typeof window !== 'undefined') {
|
||||
return window.location?.origin ?? FALLBACK
|
||||
}
|
||||
|
||||
// 4. Fallback for SSR/Node.js runtimes
|
||||
return FALLBACK
|
||||
}
|
||||
|
||||
// --- Export Constants ---
|
||||
|
||||
const { isNative } = getEnvStatus()
|
||||
const origin = getRedirectOrigin()
|
||||
|
||||
export const OIDC_CLIENT_ID = import.meta.env.VITE_OIDC_CLIENT_ID
|
||||
|| (isNative ? 'airi-stage-pocket' : 'airi-stage-web')
|
||||
|
||||
export const OIDC_REDIRECT_URI = `${origin}/auth/callback`
|
||||
|
||||
Reference in New Issue
Block a user