fix: authorization / registration

This commit is contained in:
2026-05-10 19:39:41 +03:00
parent 7720adf616
commit 5ed79d8282
3 changed files with 8 additions and 0 deletions

View File

@@ -7,6 +7,10 @@ interface CsrfResponse {
let cachedToken: string | null = null
export function clearCsrfCache(): void {
cachedToken = null
}
export async function getCsrfToken(): Promise<string> {
if (cachedToken) return cachedToken
const res = await fetch(`${API_URL}/csrf/token`, {

View File

@@ -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 })

View File

@@ -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)