diff --git a/apps/api/src/routes/auth.ts b/apps/api/src/routes/auth.ts index 4b2e29c..bbc09b4 100644 --- a/apps/api/src/routes/auth.ts +++ b/apps/api/src/routes/auth.ts @@ -80,7 +80,9 @@ function renderTauriDeepLinkPage(targetUrl: string): Response { 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`; + // Use intent://login/... to produce data URI zeavisedu://login/login?token=xxx + // which new URL() can parse (single-slash non-hierarchical URLs break WebView) + const intentUrl = `intent://login${escapedPath}#Intent;scheme=zeavisedu;package=com.zeavis.edu;S.browser_fallback_url=${encodeURIComponent(targetUrl)};end`; const html = ` diff --git a/apps/web/src/lib/tauri.ts b/apps/web/src/lib/tauri.ts index cd9ee8c..29b54e7 100644 --- a/apps/web/src/lib/tauri.ts +++ b/apps/web/src/lib/tauri.ts @@ -35,20 +35,25 @@ export async function setupDeepLinkHandler(): Promise { const { onOpenUrl } = await import('@tauri-apps/plugin-deep-link'); onOpenUrl((urls) => { for (const url of urls) { - // url looks like: zeavisedu://zeavisedu.asepharyana.my.id/login?token=xxx + // url looks like: zeavisedu://login/login?token=xxx // Extract path + query after the host try { const u = new URL(url); const target = u.pathname + u.search + u.hash; if (target && target !== '/') { window.location.href = target; + return; } - } catch { - // If URL parsing fails, try to extract everything after the scheme - const match = url.match(/^[^:]+:\/\/(?:[^/]+)?(\/.*)?$/); - if (match?.[1]) { - window.location.href = match[1]; - } + } catch { /* try fallback below */ } + + // Fallback: extract everything after scheme, handling both // and / + let match = url.match(/^[^:]+:\/\/(?:[^/]+)?(\/.*)?$/); + if (!match) { + // Also handle single-slash non-hierarchical URLs (e.g. zeavisedu:/path) + match = url.match(/^[^:]+:\/(\/.*)?$/); + } + if (match?.[1]) { + window.location.href = match[1]; } } });