fix auth
This commit is contained in:
@@ -4,6 +4,8 @@ import { AppService } from './app.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import * as Joi from 'joi';
|
||||
import {UsersModule} from "./users/user.module";
|
||||
import {AuthenticationModule} from "./authentication/authentication.module";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -17,6 +19,7 @@ import * as Joi from 'joi';
|
||||
username: configService.get<string>('POSTGRES_USER'),
|
||||
password: configService.get<string>('POSTGRES_PASSWORD'),
|
||||
database: configService.get<string>('POSTGRES_DB'),
|
||||
autoLoadEntities: true,
|
||||
ssl: {
|
||||
rejectUnauthorized: false, // Needed for Neon and similar managed DBs
|
||||
},
|
||||
@@ -28,7 +31,9 @@ import * as Joi from 'joi';
|
||||
JWT_SECRET: Joi.string().required(),
|
||||
JWT_EXPIRATION_TIME: Joi.string().required(),
|
||||
})
|
||||
})
|
||||
}),
|
||||
UsersModule,
|
||||
AuthenticationModule
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -27,4 +27,5 @@ import {UsersModule} from "../users/user.module";
|
||||
providers: [AuthenticationService, LocalStrategy, JwtStrategy] as const,
|
||||
controllers: [AuthenticationController] as const,
|
||||
})
|
||||
export class AuthenticationModule {}
|
||||
export class AuthenticationModule {
|
||||
}
|
||||
@@ -12,7 +12,8 @@ export class AuthenticationService {
|
||||
private readonly usersService: UsersService,
|
||||
private readonly jwtService: JwtService,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public async register(registrationData: RegisterDto) {
|
||||
const hashedPassword = await bcrypt.hash(registrationData.password, 10);
|
||||
@@ -30,6 +31,7 @@ export class AuthenticationService {
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
console.log(error);
|
||||
throw new HttpException(
|
||||
'Something went wrong',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
@@ -57,9 +59,8 @@ export class AuthenticationService {
|
||||
const payload: TokenPayload = {userId};
|
||||
const token = this.jwtService.sign(payload, {
|
||||
secret: this.configService.get('JWT_REFRESH_TOKEN_SECRET'),
|
||||
expiresIn: `${this.configService.get(
|
||||
'JWT_REFRESH_TOKEN_EXPIRATION_TIME',
|
||||
)}s`,
|
||||
expiresIn: this.configService.get('JWT_ACCESS_TOKEN_EXPIRATION_TIME'),
|
||||
|
||||
});
|
||||
const cookie = `Refresh=${token}; HttpOnly; Path=/; Max-Age=${this.configService.get(
|
||||
'JWT_REFRESH_TOKEN_EXPIRATION_TIME',
|
||||
|
||||
Reference in New Issue
Block a user