@@ -14,7 +14,7 @@ import {
14
14
Link ,
15
15
Panel
16
16
} from '@vkontakte/vkui'
17
- import { type ChangeEvent , type FC , useEffect , useState } from 'react'
17
+ import { type ChangeEvent , type FC , useLayoutEffect , useState } from 'react'
18
18
19
19
import { VIEW_SCHEDULE } from '../../app/routes'
20
20
import { PanelHeaderWithBack , handleResponse , isApiError } from '../../shared'
@@ -24,6 +24,7 @@ import { useSnackbar } from '../../shared/hooks'
24
24
25
25
import type { Props } from '../types.ts'
26
26
27
+ import { getToken } from '../../shared/api/client.ts'
27
28
import { loginPattern , saveData } from './helpers'
28
29
29
30
const LoginForm : FC < Props > = ( { id } ) => {
@@ -37,17 +38,23 @@ const LoginForm: FC<Props> = ({ id }) => {
37
38
const [ snackbar , showSnackbar ] = useSnackbar ( )
38
39
39
40
// biome-ignore lint/correctness/useExhaustiveDependencies: all good
40
- useEffect ( ( ) => {
41
+ useLayoutEffect ( ( ) => {
41
42
const getUserCookie = async ( ) => {
42
- const storageToken = localStorage . getItem ( 'token' )
43
+ setIsLoading ( true )
44
+ const storageToken = localStorage . getItem ( 'token' ) || getToken ( )
43
45
44
46
if ( ! storageToken ) {
45
47
showSnackbar ( {
46
48
before : < Icon28ErrorCircleOutline fill = { VKUI_RED } /> ,
47
49
subtitle : 'Заполни форму и войди в дневник' ,
48
50
title : 'О вас нет данных, ты кто такой?'
49
51
} )
52
+ setIsLoading ( false )
53
+ return
50
54
}
55
+
56
+ setIsLoading ( false )
57
+ await routeNavigator . replace ( `/${ VIEW_SCHEDULE } ` )
51
58
}
52
59
53
60
getUserCookie ( )
@@ -104,7 +111,7 @@ const LoginForm: FC<Props> = ({ id }) => {
104
111
105
112
await routeNavigator . replace ( `/${ VIEW_SCHEDULE } ` )
106
113
} catch ( error ) {
107
- console . log ( error )
114
+ console . error ( error )
108
115
} finally {
109
116
setIsLoading ( false )
110
117
}
0 commit comments