diff --git a/apps/api/src/features/auth/auth.controller.ts b/apps/api/src/features/auth/auth.controller.ts index e8ddb5a..ab08810 100644 --- a/apps/api/src/features/auth/auth.controller.ts +++ b/apps/api/src/features/auth/auth.controller.ts @@ -1,4 +1,4 @@ -// auth.controllers +// api/src/feacture/auth/auth.controller.ts import { Public } from '@/common/decorators'; import { JwtRefreshGuard } from '@/common/guards/jwt-refresh.guard'; import { RefreshTokenDto } from '@/features/auth/dto/refresh-token.dto'; @@ -57,19 +57,11 @@ export class AuthController { @HttpCode(200) @Patch('refresh') //@RequirePermissions('auth:refresh-token') - async refreshToken(@Req() req: Request,@Body() refreshTokenDto: RefreshTokenDto) { + async refreshToken(@Body() refreshTokenDto: any) { - // console.log("Pepeeeee"); - // console.log(req['user']); - // console.log("refreshTokenDto",refreshTokenDto); - // console.log(typeof refreshTokenDto); - const data = await this.authService.refreshToken(refreshTokenDto); - // console.log("data",data); - if (!data) { - return null; - } + if (!data) return null; return {tokens: data} } diff --git a/apps/web/feactures/auth/actions/refresh-token-action.ts b/apps/web/feactures/auth/actions/refresh-token-action.ts index 9d0c4f6..fc8111b 100644 --- a/apps/web/feactures/auth/actions/refresh-token-action.ts +++ b/apps/web/feactures/auth/actions/refresh-token-action.ts @@ -1,3 +1,4 @@ +// auth/actions/refresh-token-action.ts 'use server'; import { refreshApi } from '@/lib/refreshApi'; // Importa la nueva instancia import { @@ -7,7 +8,7 @@ import { export const resfreshTokenAction = async (refreshToken: RefreshTokenValue) => { try { - const response = await refreshApi.patch('/auth/refresh', {refresh_token: refreshToken.token}); + const response = await refreshApi.patch('/auth/refresh', refreshToken); const parsed = RefreshTokenResponseSchema.safeParse(response.data); diff --git a/apps/web/lib/auth.config.ts b/apps/web/lib/auth.config.ts index 9af330c..c24484c 100644 --- a/apps/web/lib/auth.config.ts +++ b/apps/web/lib/auth.config.ts @@ -1,4 +1,4 @@ -//auth.config +// lib/auth.config.ts import { SignInAction } from '@/feactures/auth/actions/login-action'; import { resfreshTokenAction } from '@/feactures/auth/actions/refresh-token-action'; import { CredentialsSignin, NextAuthConfig, Session, User } from 'next-auth'; @@ -147,7 +147,10 @@ const authConfig: NextAuthConfig = { // 4. Si el token de acceso ha expirado pero el refresh token es vĂ¡lido, renovar // console.log("Renovando token de acceso..."); try { - const res = await resfreshTokenAction({ token: token.refresh_token as string, user_id: token.user.id as number}); + const refresh_token = { token: token.refresh_token as string, user_id: Number(token.id) as number} + console.log(refresh_token); + + const res = await resfreshTokenAction(refresh_token); if (!res || !res.tokens) { throw new Error('Fallo en la respuesta de la API de refresco.');