feat: похуй 2.0
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { Navigate, Outlet } from 'react-router-dom'
|
||||
import { Navigate, Outlet, useLocation } from 'react-router-dom'
|
||||
import { useIsAuthenticated } from '@features/auth'
|
||||
import { ROUTES } from '@shared/config/routes'
|
||||
|
||||
export function GuestRoute() {
|
||||
const { isAuthenticated, isLoading } = useIsAuthenticated()
|
||||
const location = useLocation()
|
||||
const from = (location.state as { from?: { pathname: string } })?.from?.pathname ?? ROUTES.WALLET
|
||||
|
||||
if (isLoading) return null
|
||||
if (isAuthenticated) return <Navigate to={ROUTES.WALLET} replace />
|
||||
if (isAuthenticated) return <Navigate to={from} replace />
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
})
|
||||
|
||||
export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
|
||||
@@ -68,7 +68,6 @@ export function Converter() {
|
||||
<button
|
||||
type="button"
|
||||
className={styles.swapBtn}
|
||||
onClick={c.toggleMode}
|
||||
aria-label="Поменять направление"
|
||||
>
|
||||
<svg width={16} height={16} viewBox="0 0 16 16" fill="none">
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { useState } from 'react'
|
||||
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'
|
||||
|
||||
function extractErrorMessage(error: unknown): string {
|
||||
@@ -17,10 +15,7 @@ export function useLoginForm() {
|
||||
const [password, setPassword] = useState('')
|
||||
const [verificationCode, setVerificationCode] = useState('')
|
||||
const [codeSent, setCodeSent] = useState(false)
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const queryClient = useQueryClient()
|
||||
const from = (location.state as { from?: { pathname: string } })?.from?.pathname ?? ROUTES.WALLET
|
||||
|
||||
const startMutation = useMutation({
|
||||
mutationFn: loginStart,
|
||||
@@ -33,7 +28,6 @@ export function useLoginForm() {
|
||||
clearCsrfCache()
|
||||
tokenStore.set(access_token)
|
||||
queryClient.setQueryData(AUTH_QUERY_KEY, access_token)
|
||||
navigate(from, { replace: true })
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user