22 lines
708 B
TypeScript
22 lines
708 B
TypeScript
import jwt from 'jsonwebtoken'
|
|
import type {StringValue} from "ms";
|
|
const {sign, verify} = jwt
|
|
console.log(jwt)
|
|
// export function jwt() {}
|
|
|
|
|
|
export const generateAccessToken = (payload: object) => {
|
|
const {jwt: config} = useRuntimeConfig()
|
|
return sign(payload, config.secret, { expiresIn: config.accessExpiresIn as StringValue })
|
|
}
|
|
|
|
export const generateRefreshToken = (payload: object) => {
|
|
const {jwt: config} = useRuntimeConfig()
|
|
return sign(payload, config.secret, { expiresIn: config.refreshExpiresIn as StringValue })
|
|
}
|
|
|
|
export const verifyToken = (token: string) => {
|
|
const {jwt: config} = useRuntimeConfig()
|
|
return verify(token, config.secret) // 返回解码后的payload
|
|
}
|