Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 044b256

Browse files
committed
fix navigate
1 parent 21b6f29 commit 044b256

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

apps/web/src/pages/LoginForm/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
Link,
1515
Panel
1616
} from '@vkontakte/vkui'
17-
import { type ChangeEvent, type FC, useEffect, useState } from 'react'
17+
import { type ChangeEvent, type FC, useLayoutEffect, useState } from 'react'
1818

1919
import { VIEW_SCHEDULE } from '../../app/routes'
2020
import { PanelHeaderWithBack, handleResponse, isApiError } from '../../shared'
@@ -24,6 +24,7 @@ import { useSnackbar } from '../../shared/hooks'
2424

2525
import type { Props } from '../types.ts'
2626

27+
import { getToken } from '../../shared/api/client.ts'
2728
import { loginPattern, saveData } from './helpers'
2829

2930
const LoginForm: FC<Props> = ({ id }) => {
@@ -37,17 +38,23 @@ const LoginForm: FC<Props> = ({ id }) => {
3738
const [snackbar, showSnackbar] = useSnackbar()
3839

3940
// biome-ignore lint/correctness/useExhaustiveDependencies: all good
40-
useEffect(() => {
41+
useLayoutEffect(() => {
4142
const getUserCookie = async () => {
42-
const storageToken = localStorage.getItem('token')
43+
setIsLoading(true)
44+
const storageToken = localStorage.getItem('token') || getToken()
4345

4446
if (!storageToken) {
4547
showSnackbar({
4648
before: <Icon28ErrorCircleOutline fill={VKUI_RED} />,
4749
subtitle: 'Заполни форму и войди в дневник',
4850
title: 'О вас нет данных, ты кто такой?'
4951
})
52+
setIsLoading(false)
53+
return
5054
}
55+
56+
setIsLoading(false)
57+
await routeNavigator.replace(`/${VIEW_SCHEDULE}`)
5158
}
5259

5360
getUserCookie()
@@ -104,7 +111,7 @@ const LoginForm: FC<Props> = ({ id }) => {
104111

105112
await routeNavigator.replace(`/${VIEW_SCHEDULE}`)
106113
} catch (error) {
107-
console.log(error)
114+
console.error(error)
108115
} finally {
109116
setIsLoading(false)
110117
}

apps/web/src/shared/api/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ let globalToken: string | null = null
1111
export const setToken = (token: string) => {
1212
globalToken = token
1313
}
14+
15+
export const getToken = (): string | null => {
16+
return globalToken
17+
}
18+
1419
// @TODO: move to config
1520
export const client = treaty<App>(API_URL, {
1621
onRequest: (_path, options) => {

0 commit comments

Comments
 (0)