Skip to content

Commit

Permalink
re-add expiresIn
Browse files Browse the repository at this point in the history
  • Loading branch information
pKorsholm committed Mar 21, 2024
1 parent 9c0e3bd commit 8ba8dec
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/user/src/services/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MedusaError,
ModulesSdkUtils,
arrayDifference,
isString,
} from "@medusajs/utils"
import jwt, { JwtPayload } from "jsonwebtoken"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -151,6 +148,7 @@ export default class InviteService<

private generateToken(data: any): string {
const jwtSecret: string = this.getOption("jwt_secret")
const expiresIn: number = this.getValidDuration() / 1000

if (!jwtSecret) {
throw new MedusaError(
Expand All @@ -161,9 +159,17 @@ export default class InviteService<

return jwt.sign(data, jwtSecret, {
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")

Expand Down

0 comments on commit 8ba8dec

Please sign in to comment.