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