From 5ed79d8282101527e3f6aa768a15b1ecdc947a94 Mon Sep 17 00:00:00 2001 From: rassadin11 Date: Sun, 10 May 2026 19:39:41 +0300 Subject: [PATCH] fix: authorization / registration --- src/shared/api/csrf.ts | 4 ++++ src/widgets/login-form/model/useLoginForm.ts | 2 ++ src/widgets/register-form/model/useRegisterForm.ts | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/shared/api/csrf.ts b/src/shared/api/csrf.ts index 52601d4..e21e6b1 100644 --- a/src/shared/api/csrf.ts +++ b/src/shared/api/csrf.ts @@ -7,6 +7,10 @@ interface CsrfResponse { let cachedToken: string | null = null +export function clearCsrfCache(): void { + cachedToken = null +} + export async function getCsrfToken(): Promise { if (cachedToken) return cachedToken const res = await fetch(`${API_URL}/csrf/token`, { diff --git a/src/widgets/login-form/model/useLoginForm.ts b/src/widgets/login-form/model/useLoginForm.ts index 1a3fa4f..47e793a 100644 --- a/src/widgets/login-form/model/useLoginForm.ts +++ b/src/widgets/login-form/model/useLoginForm.ts @@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query' import { useNavigate, useLocation } from 'react-router-dom' import { loginStart, loginComplete, AUTH_QUERY_KEY } from '@features/auth' import { tokenStore } from '@shared/api/tokenStore' +import { clearCsrfCache } from '@shared/api/csrf' import { ROUTES } from '@shared/config/routes' import type { ApiErrorResponse } from '@shared/api/types' @@ -29,6 +30,7 @@ export function useLoginForm() { const completeMutation = useMutation({ mutationFn: loginComplete, onSuccess: ({ access_token }) => { + clearCsrfCache() tokenStore.set(access_token) queryClient.setQueryData(AUTH_QUERY_KEY, access_token) navigate(from, { replace: true }) diff --git a/src/widgets/register-form/model/useRegisterForm.ts b/src/widgets/register-form/model/useRegisterForm.ts index 3c72e06..c12791c 100644 --- a/src/widgets/register-form/model/useRegisterForm.ts +++ b/src/widgets/register-form/model/useRegisterForm.ts @@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query' import { useNavigate } from 'react-router-dom' import { registrationStart, registrationComplete, AUTH_QUERY_KEY } from '@features/auth' import { tokenStore } from '@shared/api/tokenStore' +import { clearCsrfCache } from '@shared/api/csrf' import { ROUTES } from '@shared/config/routes' import type { ApiErrorResponse } from '@shared/api/types' @@ -29,6 +30,7 @@ export function useRegisterForm() { const completeMutation = useMutation({ mutationFn: registrationComplete, onSuccess: ({ access_token }) => { + clearCsrfCache() tokenStore.set(access_token) queryClient.setQueryData(AUTH_QUERY_KEY, access_token) navigate(ROUTES.WALLET)