tokenRefresh, crear y editar productos con img funcionando

This commit is contained in:
2025-08-21 14:57:55 -04:00
parent 6a28e141a9
commit c45307d47d
22 changed files with 301 additions and 193 deletions

View File

@@ -57,13 +57,20 @@ export class AuthController {
@Patch('refresh')
//@RequirePermissions('auth:refresh-token')
async refreshToken(@Req() req: Request,@Body() refreshTokenDto: RefreshTokenDto) {
console.log("Pepe");
console.log(req['user']);
//console.log(refreshTokenDto);
return null
// console.log("Pepeeeee");
// console.log(req['user']);
// console.log("refreshTokenDto",refreshTokenDto);
// console.log(typeof refreshTokenDto);
// return await this.authService.refreshToken(refreshTokenDto);
const data = await this.authService.refreshToken(refreshTokenDto,req['user'].sub);
// console.log("data",data);
if (!data) {
return null;
}
return {tokens: data}
}
// @Public()

View File

@@ -261,8 +261,9 @@ export class AuthService {
}
//Refresh User Access Token
async refreshToken(dto: RefreshTokenDto): Promise<RefreshTokenInterface> {
const { user_id } = dto;
async refreshToken(dto: RefreshTokenDto,user_id:number): Promise<RefreshTokenInterface> {
// const { user_id } = dto;
// const user_id = 1;
const session = await this.drizzle
.select()
@@ -274,16 +275,22 @@ export class AuthService {
),
);
// console.log(session.length);
if (session.length === 0) throw new NotFoundException('session not found');
const user = await this.findUserById(dto.user_id);
const user = await this.findUserById(user_id);
if (!user) throw new NotFoundException('User not found');
// Genera token
const tokens = await this.generateTokens(user);
const decodeAccess = this.decodeToken(tokens.access_token);
const decodeRefresh = this.decodeToken(tokens.refresh_token);
// Actualiza session
await this.drizzle
.update(sessions)
.set({ sessionToken: tokens.refresh_token, expiresAt: decodeRefresh.exp })
.where(eq(sessions.userId, dto.user_id));
.where(eq(sessions.userId, user_id));
return {
access_token: tokens.access_token,