Add files via upload

This commit is contained in:
Savsis 2026-04-27 21:01:17 +05:00 • committed by GitHub
commit 675493bafc
28 changed files with 2176 additions and 0 deletions

27
hooks/useAuth.ts Normal file
View file

@ -0,0 +1,27 @@
import { useEffect } from 'react';
import { getAccessToken, getMe, clearTokens } from '../services/api';
import { useAuth } from '../store';
export function useBootAuth() {
const { setUser, setReady } = useAuth();
useEffect(() => {
(async () => {
try {
const token = await getAccessToken();
if (!token) { setReady(true); return; }
const me = await getMe();
setUser(me);
} catch {
// ignore
} finally {
setReady(true);
}
})();
}, []);
}
export async function logout() {
await clearTokens();
useAuth.getState().setUser(null);
}