Skip to content

Commit

Permalink
fix(core): Correctly parse numeric sessionDuration and verificationTo…
Browse files Browse the repository at this point in the history
…kenDuration values (#3080)
  • Loading branch information
pujux authored Sep 25, 2024
1 parent 5a4299a commit 98e4118
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ export class VerificationTokenGenerator {
* as specified in the VendureConfig.
*/
verifyVerificationToken(token: string): boolean {
const duration = ms(this.configService.authOptions.verificationTokenDuration as string);
const { verificationTokenDuration } = this.configService.authOptions;
const verificationTokenDurationInMs =
typeof verificationTokenDuration === 'string'
? ms(verificationTokenDuration)
: verificationTokenDuration;

const [generatedOn] = token.split('_');
const dateString = Buffer.from(generatedOn, 'base64').toString();
const date = new Date(dateString);
const elapsed = +new Date() - +date;
return elapsed < duration;
return elapsed < verificationTokenDurationInMs;
}
}
6 changes: 5 additions & 1 deletion packages/core/src/service/services/session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export class SessionService implements EntitySubscriberInterface {
private orderService: OrderService,
) {
this.sessionCacheStrategy = this.configService.authOptions.sessionCacheStrategy;
this.sessionDurationInMs = ms(this.configService.authOptions.sessionDuration as string);

const { sessionDuration } = this.configService.authOptions;
this.sessionDurationInMs =
typeof sessionDuration === 'string' ? ms(sessionDuration) : sessionDuration;

// This allows us to register this class as a TypeORM Subscriber while also allowing
// the injection on dependencies. See https://docs.nestjs.com/techniques/database#subscribers
this.connection.rawConnection.subscribers.push(this);
Expand Down

0 comments on commit 98e4118

Please sign in to comment.