feat: refactor admin authentication to staff authentication with updated cookie handling
This commit is contained in:
+19
-2
@@ -1,12 +1,15 @@
|
||||
import { decodeJwt } from 'jose'
|
||||
|
||||
import { userTokenCookieConfig } from '~/libs/cookie.server'
|
||||
import {
|
||||
staffTokenCookieConfig,
|
||||
userTokenCookieConfig,
|
||||
} from '~/libs/cookie.server'
|
||||
|
||||
type TTokenCookie = {
|
||||
token: string
|
||||
}
|
||||
|
||||
export const generateTokenCookie = (parameters: TTokenCookie) => {
|
||||
export const generateUserTokenCookie = (parameters: TTokenCookie) => {
|
||||
const { token } = parameters
|
||||
|
||||
const decodedToken = decodeJwt(token)
|
||||
@@ -19,3 +22,17 @@ export const generateTokenCookie = (parameters: TTokenCookie) => {
|
||||
expires: expirationDate,
|
||||
})
|
||||
}
|
||||
|
||||
export const generateStaffTokenCookie = (parameters: TTokenCookie) => {
|
||||
const { token } = parameters
|
||||
|
||||
const decodedToken = decodeJwt(token)
|
||||
const decodedTokenExp = decodedToken.exp
|
||||
const expirationDate = decodedTokenExp
|
||||
? new Date(decodedTokenExp * 1000)
|
||||
: undefined
|
||||
|
||||
return staffTokenCookieConfig.serialize(token, {
|
||||
expires: expirationDate,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user