Feat(user): Invite expiration fix (#6758)
* fix invite duration error * add changeset * undo change to auth * re-add expiresIn
This commit is contained in:
5
.changeset/breezy-clocks-applaud.md
Normal file
5
.changeset/breezy-clocks-applaud.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/user": patch
|
||||
---
|
||||
|
||||
feat(user): invite expiry fix
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
arrayDifference,
|
||||
isString,
|
||||
} from "@medusajs/utils"
|
||||
import jwt, { JwtPayload } from "jsonwebtoken"
|
||||
|
||||
@@ -17,7 +18,7 @@ type InjectedDependencies = {
|
||||
}
|
||||
|
||||
// 1 day
|
||||
const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24
|
||||
const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24 * 1000
|
||||
|
||||
export default class InviteService<
|
||||
TEntity extends Invite = Invite
|
||||
@@ -71,9 +72,7 @@ export default class InviteService<
|
||||
|
||||
const invites = await super.create(data_, context)
|
||||
|
||||
const expiresIn: number =
|
||||
parseInt(this.getOption("valid_duration")) ||
|
||||
DEFAULT_VALID_INVITE_DURATION
|
||||
const expiresIn: number = this.getValidDuration()
|
||||
|
||||
const updates = invites.map((invite) => {
|
||||
return {
|
||||
@@ -113,9 +112,7 @@ export default class InviteService<
|
||||
}
|
||||
}
|
||||
|
||||
const expiresIn: number =
|
||||
parseInt(this.getOption("valid_duration")) ||
|
||||
DEFAULT_VALID_INVITE_DURATION
|
||||
const expiresIn: number = this.getValidDuration()
|
||||
|
||||
const updates = invites.map((invite) => {
|
||||
return {
|
||||
@@ -151,9 +148,7 @@ export default class InviteService<
|
||||
|
||||
private generateToken(data: any): string {
|
||||
const jwtSecret: string = this.getOption("jwt_secret")
|
||||
const expiresIn: number =
|
||||
parseInt(this.getOption("valid_duration")) ||
|
||||
DEFAULT_VALID_INVITE_DURATION
|
||||
const expiresIn: number = this.getValidDuration() / 1000
|
||||
|
||||
if (!jwtSecret) {
|
||||
throw new MedusaError(
|
||||
@@ -163,11 +158,18 @@ export default class InviteService<
|
||||
}
|
||||
|
||||
return jwt.sign(data, jwtSecret, {
|
||||
expiresIn,
|
||||
jwtid: crypto.randomUUID(),
|
||||
expiresIn,
|
||||
})
|
||||
}
|
||||
|
||||
private getValidDuration(): number {
|
||||
return (
|
||||
parseInt(this.getOption("valid_duration")) ||
|
||||
DEFAULT_VALID_INVITE_DURATION
|
||||
)
|
||||
}
|
||||
|
||||
private validateToken(data: any): JwtPayload {
|
||||
const jwtSecret = this.getOption("jwt_secret")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user