diff --git a/apps/api/src/routes/auth.ts b/apps/api/src/routes/auth.ts index 6a80ddc..4b2e29c 100644 --- a/apps/api/src/routes/auth.ts +++ b/apps/api/src/routes/auth.ts @@ -64,23 +64,38 @@ function decodeGoogleIdToken(idToken: string): GoogleIdPayload { } /** - * Render a page for the Android system browser that redirects back to the - * Tauri app via a custom scheme (zeavisedu://). The app's AndroidManifest - * must register an intent filter for this scheme. + * Render a page for the Android system browser that uses Chrome's native + * `intent://` protocol to open the Tauri app with the session URL. + * Falls back to a clickable button if the intent is blocked. */ function renderTauriDeepLinkPage(targetUrl: string): Response { - // Rewrite https://... to zeavisedu://... for the custom scheme - const deepLink = targetUrl.replace(/^https?:\/\//, 'zeavisedu://'); + // Extract the path + query from the full URL for the intent + let pathAndQuery = '/login'; + try { + const u = new URL(targetUrl); + pathAndQuery = u.pathname + u.search + u.hash; + } catch { /* use default */ } + + const displayUrl = targetUrl.replace(/"/g, '"'); + const escapedPath = pathAndQuery.replace(/"/g, '"'); + // intent:// scheme: Chrome on Android opens the target app by package name + // browser_fallback_url: shown if the app isn't installed + const intentUrl = `intent:${escapedPath}#Intent;scheme=zeavisedu;package=com.zeavis.edu;S.browser_fallback_url=${encodeURIComponent(targetUrl)};end`; + const html = `
Login berhasil!
Kembali ke aplikasi...
Jika tombol tidak berfungsi, salin URL ini:${deepLink.replace(/
Login Google berhasil!
Kembali ke aplikasi...
Jika tombol di atas tidak berfungsi, salin dan buka URL ini di aplikasi ZeaVis Edu:
+${displayUrl.replace(//g, '>')}