mobile update

This commit is contained in:
arrelin
2026-03-10 13:54:27 +03:00
parent 6f679a5066
commit d7802cf584
76 changed files with 1503 additions and 10 deletions

View File

@@ -1,18 +1,62 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { authApi } from '../api/client';
import { useStore } from '../store/useStore';
import { Loader2, Wallet } from 'lucide-react';
import { FcGoogle } from 'react-icons/fc';
const isTauriEnv = () => typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
const DEEP_LINK_SCHEME = 'com.arrelin.family-budget-android://auth';
export default function Login() {
const { t } = useTranslation();
const { setUser } = useStore();
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
useEffect(() => {
if (!isTauriEnv()) return;
let unlisten: (() => void) | null = null;
const setupDeepLink = async () => {
const { onOpenUrl } = await import('@tauri-apps/plugin-deep-link');
unlisten = await onOpenUrl(async (urls) => {
const url = Array.isArray(urls) ? urls[0] : urls;
if (!url.startsWith(DEEP_LINK_SCHEME)) return;
const token = new URL(url).searchParams.get('token');
if (!token) return;
try {
setLoading(true);
await authApi.mobileCallback(token);
const me = await authApi.me();
setUser(me.data);
} catch {
setError(t('login.authError'));
setLoading(false);
}
});
};
setupDeepLink();
return () => { unlisten?.(); };
}, []);
const handleGoogleLogin = async () => {
try {
setLoading(true);
setError('');
if (isTauriEnv()) {
const { open } = await import('@tauri-apps/plugin-shell');
const response = await authApi.getGoogleAuthUrl(undefined, true);
await open(response.data.url);
return;
}
const currentUrl = window.location.origin;
const response = await authApi.getGoogleAuthUrl(currentUrl);
window.location.href = response.data.url;