From 99acc43ff0f190ae79bd99f946ebdffab9c50272 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Tue, 16 Jun 2026 01:25:02 +0700 Subject: [PATCH] fix(android): use intent:// protocol for deep link return from system browser Replace custom zeavisedu:// scheme in callback HTML with Chrome's native intent:// protocol which directly opens the target Android app by package name. Includes browser_fallback_url for non-app scenarios. Also updates the HTML page with better UX: auto-redirect via JS, fallback button, and copyable URL for manual paste. Co-Authored-By: Claude --- apps/api/src/routes/auth.ts | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) 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 = ` Kembali ke ZeaVis Edu -
-

Login berhasil!
Kembali ke aplikasi...

-Buka ZeaVis Edu -

Jika tombol tidak berfungsi, salin URL ini:
${deepLink.replace(/

+
+

Login Google berhasil!
Kembali ke aplikasi...

+Buka ZeaVis Edu +

Jika tombol di atas tidak berfungsi, salin dan buka URL ini di aplikasi ZeaVis Edu:

+${displayUrl.replace(//g, '>')}
- + `; return new Response(html, { status: 200,