/
DaniilSk
/
DesignLab
Обзор
Документация
Войти
/
DaniilSk
/
DesignLab
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
admin-frontend/src/stores/auth.ts
43 строки
1 KB
Даниил
feat(admin): initialize admin frontend
13 июл 2026, 23:42
13 июл 2026, 23:42
1cc58f6
Код
Авторство
О чём код?
import { defineStore } from 'pinia' import { getMe, login, logout } from '@/shared/api/admin' import { getAdminToken } from '@/shared/api/client' export const useAuthStore = defineStore('auth', { state: () => ({ username: null as string | null, isLoading: false, error: null as string | null, }), getters: { isAuthenticated: (state) => Boolean(state.username || getAdminToken()), }, actions: { async restore() { if (!getAdminToken()) return try { const me = await getMe() this.username = me.username } catch { this.username = null } }, async login(username: string, password: string) { this.isLoading = true this.error = null try { const data = await login(username, password) this.username = data.username } catch (error) { this.error = error instanceof Error ? error.message : 'Ошибка входа' throw error } finally { this.isLoading = false } }, async logout() { await logout() this.username = null }, }, })