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:
Stevche Radevski
2024-09-06 12:58:57 +02:00
committed by GitHub
parent 3ba0ddcd43
commit 62e0c593c8
10 changed files with 136 additions and 50 deletions
+10 -2
View File
@@ -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,
})