cambios en el refresh token
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// auth.controllers
|
||||
import { Public } from '@/common/decorators';
|
||||
import { JwtRefreshGuard } from '@/common/guards/jwt-refresh.guard';
|
||||
import { RefreshTokenDto } from '@/features/auth/dto/refresh-token.dto';
|
||||
@@ -51,7 +52,7 @@ export class AuthController {
|
||||
// return { message: 'Password reset link sent to your email' };
|
||||
// }
|
||||
|
||||
@UseGuards(JwtRefreshGuard)
|
||||
// @UseGuards(JwtRefreshGuard)
|
||||
@Public()
|
||||
@HttpCode(200)
|
||||
@Patch('refresh')
|
||||
@@ -63,7 +64,7 @@ export class AuthController {
|
||||
// console.log("refreshTokenDto",refreshTokenDto);
|
||||
// console.log(typeof refreshTokenDto);
|
||||
|
||||
const data = await this.authService.refreshToken(refreshTokenDto,req['user'].sub);
|
||||
const data = await this.authService.refreshToken(refreshTokenDto);
|
||||
// console.log("data",data);
|
||||
|
||||
if (!data) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// auth.service
|
||||
import { envs } from '@/common/config/envs';
|
||||
import { Env, validateString } from '@/common/utils';
|
||||
import { DRIZZLE_PROVIDER } from '@/database/drizzle-provider';
|
||||
@@ -261,10 +262,16 @@ export class AuthService {
|
||||
}
|
||||
|
||||
//Refresh User Access Token
|
||||
async refreshToken(dto: RefreshTokenDto,user_id:number): Promise<RefreshTokenInterface> {
|
||||
// const { user_id } = dto;
|
||||
async refreshToken(dto: RefreshTokenDto): Promise<RefreshTokenInterface> {
|
||||
const { user_id, refresh_token } = dto;
|
||||
// const user_id = 1;
|
||||
|
||||
const validation = await this.jwtService.verifyAsync(refresh_token, {
|
||||
secret: envs.refresh_token_secret,
|
||||
});
|
||||
|
||||
if (!validation) throw new UnauthorizedException('Invalid refresh token');
|
||||
|
||||
const session = await this.drizzle
|
||||
.select()
|
||||
.from(sessions)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// refresh-token
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNumber, IsString } from 'class-validator';
|
||||
|
||||
@@ -8,7 +9,7 @@ export class RefreshTokenDto {
|
||||
})
|
||||
refresh_token: string;
|
||||
|
||||
// @ApiProperty()
|
||||
// @IsNumber()
|
||||
// user_id: number;
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
user_id: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user