env файлы
This commit is contained in:
parent
64cd684fc8
commit
e7fc8553fb
|
|
@ -1,5 +1,5 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AuthService } from './auth.service';
|
||||
import { AuthController } from './auth.controller';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
|
|
@ -13,9 +13,13 @@ import { RefreshTokenStoreService } from './refresh-token-store.service';
|
|||
imports: [
|
||||
ConfigModule,
|
||||
UsersModule,
|
||||
JwtModule.register({
|
||||
secret: jwtConstants.secret,
|
||||
signOptions: { expiresIn: jwtConstants.accessTokenExpiresIn },
|
||||
JwtModule.registerAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
secret: configService.get<string>('JWT_SECRET'),
|
||||
signOptions: { expiresIn: jwtConstants.accessTokenExpiresIn },
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
],
|
||||
controllers: [AuthController],
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {
|
|||
} from '@nestjs/common';
|
||||
import { UsersService } from '../users/users.service';
|
||||
import { User } from 'src/users/user.entity';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { VerificationStoreService } from './verification-store.service';
|
||||
import { SmsService } from './sms.service';
|
||||
|
|
@ -24,6 +25,7 @@ export class AuthService {
|
|||
constructor(
|
||||
private usersService: UsersService,
|
||||
private jwtService: JwtService,
|
||||
private configService: ConfigService,
|
||||
private verificationStore: VerificationStoreService,
|
||||
private smsService: SmsService,
|
||||
private refreshTokenStore: RefreshTokenStoreService,
|
||||
|
|
@ -108,7 +110,7 @@ export class AuthService {
|
|||
throw new BadRequestException('Недействительный или просроченный refresh token');
|
||||
}
|
||||
try {
|
||||
this.jwtService.verify(refreshToken, { secret: jwtConstants.secret });
|
||||
this.jwtService.verify(refreshToken, { secret: this.configService.get<string>('JWT_SECRET') });
|
||||
} catch {
|
||||
this.refreshTokenStore.remove(refreshToken);
|
||||
throw new BadRequestException('Недействительный refresh token');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
export const jwtConstants = {
|
||||
secret: '6by876hiuGHiugiuG8t78t87tGUYUYg8u7g87',
|
||||
/** Access token: 15 минут (в секундах) */
|
||||
accessTokenExpiresIn: 15 * 60,
|
||||
/** Refresh token: 30 дней (в секундах) */
|
||||
|
|
|
|||
Loading…
Reference in New Issue