fix(android): add deep link handler to intercept zeavisedu:// URLs and navigate WebView
Login-page won't auto-process token on deep link return because the WebView stays on the page it was on. Added setupDeepLinkHandler() which listens for zeavisedu:// scheme URLs and navigates the WebView to the correct path+query. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import { MainLayout } from "@/components/layout/main-layout";
|
||||
import { useEffect } from "react";
|
||||
import { useAuthStore } from "@/store/auth-store";
|
||||
import { apiClient } from "@/lib/api-client";
|
||||
import { setupDeepLinkHandler } from "@/lib/tauri";
|
||||
|
||||
function LogoutProses() {
|
||||
const setUser = useAuthStore((state) => state.setUser);
|
||||
@@ -161,6 +162,11 @@ function GlobalErrorTracker() {
|
||||
}
|
||||
|
||||
export function App() {
|
||||
// Register deep link handler for Android OAuth return
|
||||
useEffect(() => {
|
||||
setupDeepLinkHandler();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AuthInitializer />
|
||||
|
||||
@@ -19,7 +19,37 @@ export async function openUrl(url: string): Promise<void> {
|
||||
window.location.href = url;
|
||||
return;
|
||||
}
|
||||
// Lazy-import Tauri opener only in Tauri context
|
||||
const { openUrl: tauriOpenUrl } = await import('@tauri-apps/plugin-opener');
|
||||
await tauriOpenUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for deep link URLs when the app is opened from an external link.
|
||||
* On Android, after Google OAuth completes in the system browser, the
|
||||
* callback page redirects to zeavisedu://... which triggers this listener.
|
||||
* We extract the path + query and navigate the WebView there.
|
||||
*/
|
||||
export async function setupDeepLinkHandler(): Promise<void> {
|
||||
if (!isTauri()) return;
|
||||
|
||||
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
|
||||
// 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;
|
||||
}
|
||||
} catch {
|
||||
// If URL parsing fails, try to extract everything after the scheme
|
||||
const match = url.match(/^[^:]+:\/\/(?:[^/]+)?(\/.*)?$/);
|
||||
if (match?.[1]) {
|
||||
window.location.href = match[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user