Skip to content

Commit c78b9db

Browse files
committed
refactor: inject COOKIE_EXPIRES_IN into AuthService and update cookie maxAge logic
1 parent 230901c commit c78b9db

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

server/src/auth/auth.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ export class AuthModule {
5454
DiscordStrategy,
5555
MagicLinkEmailStrategy,
5656
JwtStrategy,
57+
{
58+
inject: [ConfigService],
59+
provide: 'COOKIE_EXPIRES_IN',
60+
useFactory: (configService: ConfigService) =>
61+
configService.getOrThrow<string>('COOKIE_EXPIRES_IN'),
62+
},
5763
{
5864
provide: 'SERVER_URL',
5965
inject: [ConfigService],

server/src/auth/auth.service.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import {
2-
HttpException,
3-
HttpStatus,
4-
Inject,
5-
Injectable,
6-
Logger,
7-
} from '@nestjs/common';
1+
import { Inject, Injectable, Logger } from '@nestjs/common';
82
import { JwtService } from '@nestjs/jwt';
93
import { CreateUser } from '@shared/validation/user/dto/CreateUser.dto';
10-
import { NewEmailUserDto } from '@shared/validation/user/dto/NewEmailUser.dto';
114
import axios from 'axios';
125
import type { Request, Response } from 'express';
136

@@ -28,6 +21,8 @@ export class AuthService {
2821
private readonly userService: UserService,
2922
@Inject(JwtService)
3023
private readonly jwtService: JwtService,
24+
@Inject('COOKIE_EXPIRES_IN')
25+
private readonly COOKIE_EXPIRES_IN: string,
3126
@Inject('FRONTEND_URL')
3227
private readonly FRONTEND_URL: string,
3328

@@ -235,7 +230,7 @@ export class AuthService {
235230

236231
const frontEndURL = this.FRONTEND_URL;
237232
const domain = this.APP_DOMAIN;
238-
const maxAge = 1000 * 60 * 60 * 24 * 365;
233+
const maxAge = parseInt(this.COOKIE_EXPIRES_IN);
239234

240235
res.cookie('token', token.access_token, {
241236
domain: domain,

0 commit comments

Comments
 (0)