From 574e27a379c74bcdf281516539a29c3264462bb5 Mon Sep 17 00:00:00 2001 From: rassadin11 Date: Sun, 10 May 2026 18:52:24 +0300 Subject: [PATCH] fix: fix logout + fix protected route --- src/app/providers/ProtectedRoute.tsx | 14 ++++++++++++++ src/app/providers/RouterProvider.tsx | 12 ++++++++---- src/features/auth/api/registrationApi.ts | 6 ++++-- 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 src/app/providers/ProtectedRoute.tsx diff --git a/src/app/providers/ProtectedRoute.tsx b/src/app/providers/ProtectedRoute.tsx new file mode 100644 index 0000000..f3e020b --- /dev/null +++ b/src/app/providers/ProtectedRoute.tsx @@ -0,0 +1,14 @@ +import { Navigate, Outlet, useLocation } from 'react-router-dom' +import { useIsAuthenticated } from '@features/auth' +import { ROUTES } from '@shared/config/routes' + +export function ProtectedRoute() { + const isAuthenticated = useIsAuthenticated() + const location = useLocation() + + if (!isAuthenticated) { + return + } + + return +} diff --git a/src/app/providers/RouterProvider.tsx b/src/app/providers/RouterProvider.tsx index 1eab5f7..7025d3d 100644 --- a/src/app/providers/RouterProvider.tsx +++ b/src/app/providers/RouterProvider.tsx @@ -8,6 +8,7 @@ import { RegisterPage } from '@pages/register' import { SeedPhrasePage } from '@pages/seed-phrase' import { ROUTES } from '@shared/config/routes' import { ScrollToTop } from './ScrollToTop' +import { ProtectedRoute } from './ProtectedRoute' export function RouterProvider() { return ( @@ -15,12 +16,15 @@ export function RouterProvider() { } /> - } /> - } /> - } /> } /> } /> - } /> + + }> + } /> + } /> + } /> + } /> + ) diff --git a/src/features/auth/api/registrationApi.ts b/src/features/auth/api/registrationApi.ts index d1d1d84..160187c 100644 --- a/src/features/auth/api/registrationApi.ts +++ b/src/features/auth/api/registrationApi.ts @@ -1,4 +1,5 @@ import { api } from '@shared/api/base' +import { getCsrfToken } from '@shared/api/csrf' export interface RegistrationStartPayload { email: string @@ -19,6 +20,7 @@ export function registrationComplete(payload: RegistrationCompletePayload): Prom return api.post('/auth/registration/complete', payload) } -export function logout(): Promise { - return api.post('/logout', {}) +export async function logout(): Promise { + const csrfToken = await getCsrfToken() + return api.post('/logout', { _csrf: csrfToken }) }