feat: add environment configuration and implement cookie handling for user authentication

This commit is contained in:
Ardeman
2025-02-27 19:37:31 +08:00
parent 9386b8dd69
commit f9d861f24d
15 changed files with 213 additions and 30 deletions
+21
View File
@@ -0,0 +1,21 @@
import { decodeJwt } from 'jose'
import { userTokenCookieConfig } from '~/libs/cookie.server'
type TTokenCookie = {
token: string
}
export const generateTokenCookie = (parameters: TTokenCookie) => {
const { token } = parameters
const decodedToken = decodeJwt(token)
const decodedTokenExp = decodedToken.exp
const expirationDate = decodedTokenExp
? new Date(decodedTokenExp * 1000)
: undefined
return userTokenCookieConfig.serialize(token, {
expires: expirationDate,
})
}