refresh token arreglado
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// auth.controllers
|
// api/src/feacture/auth/auth.controller.ts
|
||||||
import { Public } from '@/common/decorators';
|
import { Public } from '@/common/decorators';
|
||||||
import { JwtRefreshGuard } from '@/common/guards/jwt-refresh.guard';
|
import { JwtRefreshGuard } from '@/common/guards/jwt-refresh.guard';
|
||||||
import { RefreshTokenDto } from '@/features/auth/dto/refresh-token.dto';
|
import { RefreshTokenDto } from '@/features/auth/dto/refresh-token.dto';
|
||||||
@@ -57,19 +57,11 @@ export class AuthController {
|
|||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@Patch('refresh')
|
@Patch('refresh')
|
||||||
//@RequirePermissions('auth:refresh-token')
|
//@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);
|
const data = await this.authService.refreshToken(refreshTokenDto);
|
||||||
// console.log("data",data);
|
|
||||||
|
|
||||||
if (!data) {
|
if (!data) return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {tokens: data}
|
return {tokens: data}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// auth/actions/refresh-token-action.ts
|
||||||
'use server';
|
'use server';
|
||||||
import { refreshApi } from '@/lib/refreshApi'; // Importa la nueva instancia
|
import { refreshApi } from '@/lib/refreshApi'; // Importa la nueva instancia
|
||||||
import {
|
import {
|
||||||
@@ -7,7 +8,7 @@ import {
|
|||||||
|
|
||||||
export const resfreshTokenAction = async (refreshToken: RefreshTokenValue) => {
|
export const resfreshTokenAction = async (refreshToken: RefreshTokenValue) => {
|
||||||
try {
|
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);
|
const parsed = RefreshTokenResponseSchema.safeParse(response.data);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//auth.config
|
// lib/auth.config.ts
|
||||||
import { SignInAction } from '@/feactures/auth/actions/login-action';
|
import { SignInAction } from '@/feactures/auth/actions/login-action';
|
||||||
import { resfreshTokenAction } from '@/feactures/auth/actions/refresh-token-action';
|
import { resfreshTokenAction } from '@/feactures/auth/actions/refresh-token-action';
|
||||||
import { CredentialsSignin, NextAuthConfig, Session, User } from 'next-auth';
|
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
|
// 4. Si el token de acceso ha expirado pero el refresh token es válido, renovar
|
||||||
// console.log("Renovando token de acceso...");
|
// console.log("Renovando token de acceso...");
|
||||||
try {
|
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) {
|
if (!res || !res.tokens) {
|
||||||
throw new Error('Fallo en la respuesta de la API de refresco.');
|
throw new Error('Fallo en la respuesta de la API de refresco.');
|
||||||
|
|||||||
Reference in New Issue
Block a user