feat: enhance admin login flow with conditional redirects based on authentication status
This commit is contained in:
parent
5007b8d4db
commit
1bebe61634
@ -1,17 +1,4 @@
|
|||||||
import { redirect } from 'react-router'
|
|
||||||
|
|
||||||
import { handleCookie } from '~/libs/cookies'
|
|
||||||
import { AdminLoginPage } from '~/pages/admin-login'
|
import { AdminLoginPage } from '~/pages/admin-login'
|
||||||
|
|
||||||
import type { Route } from './+types/_admin.lg-admin._auth.login'
|
|
||||||
|
|
||||||
export const loader = async ({ request }: Route.LoaderArgs) => {
|
|
||||||
const { staffToken } = await handleCookie(request)
|
|
||||||
|
|
||||||
if (staffToken) {
|
|
||||||
throw redirect('/lg-admin')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const AuthLayout = () => <AdminLoginPage />
|
const AuthLayout = () => <AdminLoginPage />
|
||||||
export default AuthLayout
|
export default AuthLayout
|
||||||
|
|||||||
@ -18,6 +18,10 @@ export const loader = async ({ request }: Route.LoaderArgs) => {
|
|||||||
throw redirect('/lg-admin/login')
|
throw redirect('/lg-admin/login')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isAuthPage && staffToken) {
|
||||||
|
throw redirect('/lg-admin')
|
||||||
|
}
|
||||||
|
|
||||||
if (staffToken) {
|
if (staffToken) {
|
||||||
const { data } = await getStaff({
|
const { data } = await getStaff({
|
||||||
accessToken: staffToken,
|
accessToken: staffToken,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user