feat: enhance admin login flow with conditional redirects based on authentication status

This commit is contained in:
Ardeman 2025-03-03 17:50:10 +08:00
parent 5007b8d4db
commit 1bebe61634
2 changed files with 4 additions and 13 deletions

View File

@ -1,17 +1,4 @@
import { redirect } from 'react-router'
import { handleCookie } from '~/libs/cookies'
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 />
export default AuthLayout

View File

@ -18,6 +18,10 @@ export const loader = async ({ request }: Route.LoaderArgs) => {
throw redirect('/lg-admin/login')
}
if (isAuthPage && staffToken) {
throw redirect('/lg-admin')
}
if (staffToken) {
const { data } = await getStaff({
accessToken: staffToken,