|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
import { createContext, useContext, useState, useCallback, useEffect, type ReactNode } from 'react'
|
|
|
import type { User } from '@/types'
|
|
|
-import { api, setAccessToken, refreshAccessToken } from '@/lib/api'
|
|
|
+import { api, setAccessToken, refreshAccessToken, hasSessionCookie } from '@/lib/api'
|
|
|
|
|
|
/**
|
|
|
* Состояние аутентификации, доступное через контекст
|
|
|
@@ -34,6 +34,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|
|
const [isLoading, setIsLoading] = useState(true)
|
|
|
|
|
|
const refreshSession = useCallback(async () => {
|
|
|
+ if (!hasSessionCookie()) {
|
|
|
+ setIsLoading(false)
|
|
|
+ return
|
|
|
+ }
|
|
|
try {
|
|
|
const newToken = await refreshAccessToken()
|
|
|
setAccessToken(newToken)
|
|
|
@@ -64,8 +68,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|
|
const logout = useCallback(async () => {
|
|
|
try {
|
|
|
await api.post('/auth/logout', {})
|
|
|
- } catch (e) {
|
|
|
- console.warn('logout failed', e)
|
|
|
+ } catch {
|
|
|
}
|
|
|
setAccessToken(null)
|
|
|
setUser(null)
|