refactor: standardize access token variable naming across routes

This commit is contained in:
Ardeman
2025-03-12 20:46:54 +08:00
parent f423f3e1c0
commit 1ce5a2130b
22 changed files with 127 additions and 94 deletions
+5 -7
View File
@@ -10,16 +10,14 @@ import { setStaffLogoutHeaders } from '~/libs/logout-header.server'
import type { Route } from './+types/_admin.lg-admin'
export const loader = async ({ request }: Route.LoaderArgs) => {
const { staffToken } = await handleCookie(request)
const { staffToken: accessToken } = await handleCookie(request)
const { pathname } = new URL(request.url)
const isAuthPage = AUTH_PAGES.includes(pathname)
let staffData
if (staffToken) {
if (accessToken) {
try {
const { data } = await getStaff({
accessToken: staffToken,
})
const { data } = await getStaff({ accessToken })
staffData = data
} catch (error) {
if (error instanceof XiorError && error.response?.status === 401) {
@@ -28,11 +26,11 @@ export const loader = async ({ request }: Route.LoaderArgs) => {
}
}
if (!isAuthPage && !staffToken) {
if (!isAuthPage && !accessToken) {
throw redirect('/lg-admin/login')
}
if (isAuthPage && staffToken) {
if (isAuthPage && accessToken) {
throw redirect('/lg-admin')
}