This commit is contained in:
@@ -76,13 +76,19 @@ export const AuthProvider: Component<AuthProviderProps> = (props) => {
|
||||
// Инициализация авторизации при монтировании
|
||||
onMount(async () => {
|
||||
console.log('[AuthProvider] Performing auth initialization...')
|
||||
|
||||
|
||||
// 🍪 Для httpOnly cookies проверяем авторизацию через GraphQL запрос
|
||||
try {
|
||||
console.log('[AuthProvider] Checking authentication via GraphQL...')
|
||||
|
||||
// Делаем тестовый запрос для проверки авторизации
|
||||
const result = await query<{ me: { id: string } | null }>(`${location.origin}/graphql`, `
|
||||
|
||||
// Добавляем таймаут для запроса
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Auth check timeout')), 10000)
|
||||
)
|
||||
|
||||
const authPromise = query<{ me: { id: string } | null }>(
|
||||
`${location.origin}/graphql`,
|
||||
`
|
||||
query CheckAuth {
|
||||
me {
|
||||
id
|
||||
@@ -90,8 +96,14 @@ export const AuthProvider: Component<AuthProviderProps> = (props) => {
|
||||
email
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
`
|
||||
)
|
||||
|
||||
// Делаем тестовый запрос для проверки авторизации с таймаутом
|
||||
const result = (await Promise.race([authPromise, timeoutPromise])) as {
|
||||
me: { id: string; name: string; email: string } | null
|
||||
}
|
||||
|
||||
if (result?.me?.id) {
|
||||
console.log('[AuthProvider] User authenticated via httpOnly cookie:', result.me.id)
|
||||
setIsAuthenticated(true)
|
||||
@@ -102,10 +114,11 @@ export const AuthProvider: Component<AuthProviderProps> = (props) => {
|
||||
} catch (error) {
|
||||
console.log('[AuthProvider] Authentication check failed:', error)
|
||||
setIsAuthenticated(false)
|
||||
} finally {
|
||||
// Всегда устанавливаем ready в true, даже при ошибке
|
||||
console.log('[AuthProvider] Auth initialization complete, ready for requests')
|
||||
setIsReady(true)
|
||||
}
|
||||
|
||||
console.log('[AuthProvider] Auth initialization complete, ready for requests')
|
||||
setIsReady(true)
|
||||
})
|
||||
|
||||
const login = async (username: string, password: string) => {
|
||||
|
||||
Reference in New Issue
Block a user