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