feat: add admin login page and authentication logic with form handling
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Outlet } from 'react-router'
|
||||
import { Outlet, redirect } from 'react-router'
|
||||
|
||||
import { getStaff } from '~/apis/admin/get-staff'
|
||||
import { AUTH_PAGES } from '~/configs/pages'
|
||||
import { AdminProvider } from '~/contexts/admin'
|
||||
import { AdminDefaultLayout } from '~/layouts/admin/default'
|
||||
import { handleCookie } from '~/libs/cookies'
|
||||
@@ -9,7 +10,14 @@ import type { Route } from './+types/_admin.lg-admin'
|
||||
|
||||
export const loader = async ({ request }: Route.LoaderArgs) => {
|
||||
const { adminToken } = await handleCookie(request)
|
||||
const { pathname } = new URL(request.url)
|
||||
const isAuthPage = AUTH_PAGES.includes(pathname)
|
||||
let adminData
|
||||
|
||||
if (!isAuthPage && !adminToken) {
|
||||
throw redirect('/lg-admin/login')
|
||||
}
|
||||
|
||||
if (adminToken) {
|
||||
const { data } = await getStaff({
|
||||
accessToken: adminToken,
|
||||
|
||||
Reference in New Issue
Block a user