feat: update cookie paths for staff authentication and implement redirect logic in admin login
This commit is contained in:
parent
599a92fba3
commit
5007b8d4db
@ -15,5 +15,5 @@ export const staffTokenCookieConfig = createCookie(STAFF_COOKIES.token, {
|
|||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
secure: process.env.NODE_ENV === 'production',
|
||||||
secrets: [process.env.VITE_SALT_KEY || 'default-secret'],
|
secrets: [process.env.VITE_SALT_KEY || 'default-secret'],
|
||||||
path: '/lg-admin',
|
path: '/',
|
||||||
})
|
})
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export const setStaffLogoutHeaders = () => {
|
|||||||
const responseHeaders = new Headers()
|
const responseHeaders = new Headers()
|
||||||
responseHeaders.append(
|
responseHeaders.append(
|
||||||
'Set-Cookie',
|
'Set-Cookie',
|
||||||
`${STAFF_COOKIES.token}=; Path=/lg-admin; HttpOnly; SameSite=Strict; Max-Age=0`,
|
`${STAFF_COOKIES.token}=; Path=/; HttpOnly; SameSite=Strict; Max-Age=0`,
|
||||||
)
|
)
|
||||||
|
|
||||||
return responseHeaders
|
return responseHeaders
|
||||||
|
|||||||
@ -1,4 +1,17 @@
|
|||||||
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user