fix teacher, parent and admin pages
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
||||
useMemo,
|
||||
useSyncExternalStore,
|
||||
} from 'react'
|
||||
import { setStoredToken, getStoredToken } from '../api/http'
|
||||
import { ApiHttpError, setStoredToken, getStoredToken } from '../api/http'
|
||||
import type { AuthUser } from '../api/types'
|
||||
import { loginRequest } from '../api/session'
|
||||
|
||||
@@ -98,7 +98,19 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot)
|
||||
|
||||
const login = useCallback(async (email: string, password: string) => {
|
||||
const result = await loginRequest(email, password)
|
||||
let result: Awaited<ReturnType<typeof loginRequest>>
|
||||
try {
|
||||
result = await loginRequest(email, password)
|
||||
} catch (e) {
|
||||
const message =
|
||||
e instanceof ApiHttpError
|
||||
? e.message
|
||||
: e instanceof Error
|
||||
? e.message
|
||||
: 'Could not reach the server.'
|
||||
return { ok: false as const, message }
|
||||
}
|
||||
|
||||
if (result.status === false) {
|
||||
return {
|
||||
ok: false as const,
|
||||
|
||||
Reference in New Issue
Block a user