feat: Add support for refreshing JWT tokens (#9013)
* feat: Add support for refreshing JWT tokens * feat: Add refresh method to the auth SDK
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
import jwt from "jsonwebtoken"
|
||||
import { MedusaError } from "../common"
|
||||
|
||||
export const generateJwtToken = (
|
||||
tokenPayload: Record<string, unknown>,
|
||||
jwtConfig: {
|
||||
secret: string
|
||||
expiresIn: string
|
||||
secret: string | undefined
|
||||
expiresIn: string | undefined
|
||||
}
|
||||
) => {
|
||||
if (!jwtConfig.secret || !jwtConfig.expiresIn) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_ARGUMENT,
|
||||
"JWT secret and expiresIn must be provided when generating a token"
|
||||
)
|
||||
}
|
||||
|
||||
return jwt.sign(tokenPayload, jwtConfig.secret, {
|
||||
expiresIn: jwtConfig.expiresIn,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user