mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
Update auth.ts
This commit is contained in:
@@ -2,6 +2,7 @@ import { create } from 'zustand'
|
|||||||
import { persist } from 'zustand/middleware'
|
import { persist } from 'zustand/middleware'
|
||||||
import type { User } from '../types'
|
import type { User } from '../types'
|
||||||
import { authApi } from '../api/auth'
|
import { authApi } from '../api/auth'
|
||||||
|
import { apiClient } from '../api/client'
|
||||||
import { tokenStorage, isTokenValid, tokenRefreshManager } from '../utils/token'
|
import { tokenStorage, isTokenValid, tokenRefreshManager } from '../utils/token'
|
||||||
|
|
||||||
export interface TelegramWidgetData {
|
export interface TelegramWidgetData {
|
||||||
@@ -89,15 +90,9 @@ export const useAuthStore = create<AuthState>()(
|
|||||||
set({ isAdmin: false })
|
set({ isAdmin: false })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const response = await fetch('/api/cabinet/auth/me/is-admin', {
|
// Используем apiClient для единообразной обработки ошибок
|
||||||
headers: {
|
const response = await apiClient.get<{ is_admin: boolean }>('/cabinet/auth/me/is-admin')
|
||||||
Authorization: `Bearer ${token}`,
|
set({ isAdmin: response.data.is_admin })
|
||||||
},
|
|
||||||
})
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json()
|
|
||||||
set({ isAdmin: data.is_admin })
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Auth] Failed to check admin status:', error)
|
console.error('[Auth] Failed to check admin status:', error)
|
||||||
set({ isAdmin: false })
|
set({ isAdmin: false })
|
||||||
|
|||||||
Reference in New Issue
Block a user