diff --git a/apps/api/src/common/guards/jwt-refresh.guard.ts b/apps/api/src/common/guards/jwt-refresh.guard.ts index b0612db..ecdc435 100644 --- a/apps/api/src/common/guards/jwt-refresh.guard.ts +++ b/apps/api/src/common/guards/jwt-refresh.guard.ts @@ -24,7 +24,7 @@ export class JwtRefreshGuard implements CanActivate { const request = context.switchToHttp().getRequest(); const token = this.extractTokenFromHeader(request); if (!token) { - throw new UnauthorizedException(); + throw new UnauthorizedException('No Refresh Token?'); } try { request.user = await this.jwtService.verifyAsync(token, { @@ -43,8 +43,8 @@ export class JwtRefreshGuard implements CanActivate { } private extractTokenFromHeader(request: Request): string | undefined { - const token = request.body.token - console.log(token); + const token = request.body.refresh_token + // console.log(token); if (token) { return token; diff --git a/apps/api/src/features/auth/auth.controller.ts b/apps/api/src/features/auth/auth.controller.ts index abe1c0e..d22c33c 100644 --- a/apps/api/src/features/auth/auth.controller.ts +++ b/apps/api/src/features/auth/auth.controller.ts @@ -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() diff --git a/apps/api/src/features/auth/auth.service.ts b/apps/api/src/features/auth/auth.service.ts index 622fd01..146fc64 100644 --- a/apps/api/src/features/auth/auth.service.ts +++ b/apps/api/src/features/auth/auth.service.ts @@ -261,8 +261,9 @@ export class AuthService { } //Refresh User Access Token - async refreshToken(dto: RefreshTokenDto): Promise { - const { user_id } = dto; + async refreshToken(dto: RefreshTokenDto,user_id:number): Promise { + // 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, diff --git a/apps/api/src/features/inventory/dto/create-product.dto.ts b/apps/api/src/features/inventory/dto/create-product.dto.ts index 487d1a1..b8b161b 100644 --- a/apps/api/src/features/inventory/dto/create-product.dto.ts +++ b/apps/api/src/features/inventory/dto/create-product.dto.ts @@ -39,15 +39,10 @@ export class CreateProductDto { status: string; @ApiProperty() - @IsInt({ - message: 'userID must be a number', - }) - // @IsOptional() + @IsOptional() userId: number; @ApiProperty() - @IsString({ - message: 'urlImg must be a string', - }) + @IsOptional() urlImg: string; } diff --git a/apps/api/src/features/inventory/inventory.controller.ts b/apps/api/src/features/inventory/inventory.controller.ts index 738bd65..2865279 100644 --- a/apps/api/src/features/inventory/inventory.controller.ts +++ b/apps/api/src/features/inventory/inventory.controller.ts @@ -52,43 +52,34 @@ export class UsersController { } @Post() - // @Roles('admin') @ApiOperation({ summary: 'Create a new product' }) @ApiResponse({ status: 201, description: 'Product created successfully.' }) + @ApiResponse({ status: 500, description: 'Internal server error.' }) + @UseInterceptors(FilesInterceptor('urlImg')) async create( + @Req() req: Request, @Body() createUserDto: CreateProductDto, + @UploadedFiles() files: Express.Multer.File[], @Query('roleId') roleId?: string, ) { - const data = await this.inventoryService.create(createUserDto) + const id = Number(req['user'].id); + const data = await this.inventoryService.create(files,createUserDto,id) return { message: 'User created successfully', data }; } - @Patch('/id/:id') - // @Roles('admin') - @ApiOperation({ summary: 'Update a product' }) - @ApiResponse({ status: 200, description: 'Product updated successfully.' }) - @ApiResponse({ status: 404, description: 'Product not found.' }) - async update(@Param('id') id: string, @Body() UpdateProductDto: UpdateProductDto) { - const data = await this.inventoryService.update(id, UpdateProductDto); - return { message: 'User updated successfully', data }; - } - @Patch('/upload') @ApiOperation({ summary: 'Update a product' }) @ApiResponse({ status: 200, description: 'Product uploaded successfully.'}) @ApiResponse({ status: 404, description: 'Product not found.' }) @ApiResponse({ status: 500, description: 'Internal server error.' }) @UseInterceptors(FilesInterceptor('urlImg')) - async uploadFile(@Req() req: Request, @UploadedFiles() files: Express.Multer.File[], @Body() body: any) { - // Aquí puedes acceder a los campos del formulario - // console.log('Archivos:', files); + async uploadFile( + @Req() req: Request, + @UploadedFiles() files: Express.Multer.File[], + @Body() body: any + ) { const id = Number(req['user'].id); - // console.log(req['user'].id) - // console.log('Otros campos del formulario:', body); const result = await this.inventoryService.saveImages(files,body,id); - - // const result = ['result'] - return { data: result }; } diff --git a/apps/api/src/features/inventory/inventory.service.ts b/apps/api/src/features/inventory/inventory.service.ts index 0742d45..4d3eac5 100644 --- a/apps/api/src/features/inventory/inventory.service.ts +++ b/apps/api/src/features/inventory/inventory.service.ts @@ -187,63 +187,92 @@ export class InventoryService { // Rest of the service remains the same async create( - createProductDto: CreateProductDto + file: Express.Multer.File[], + createProductDto: CreateProductDto, + userId: number, ): Promise { + let gallery: string[] = []; + + + await Promise.all(file.map(async (f, index) => { + const fileName = `${index + 1}-${f.originalname}`; + gallery.push(fileName); + })); + + console.log(gallery); + // Start a transaction return await this.drizzle.transaction(async (tx) => { + const productValue = { + title: createProductDto.title, + description: createProductDto.description, + price: createProductDto.price, + address: createProductDto.address, + status: createProductDto.status, + urlImg: gallery[0], + stock: createProductDto.stock, + userId: userId, + gallery: gallery + } + console.log(productValue); + + const [newProduct] = await tx .insert(products) - .values({ - title: createProductDto.title, - description: createProductDto.description, - price: createProductDto.price, - address: createProductDto.address, - urlImg: createProductDto.urlImg, - stock: createProductDto.stock, - status: createProductDto.status, - userId: createProductDto.userId - }) + .values(productValue) .returning(); + + const productId = newProduct.id; + const picturesPath = join(__dirname, '..', '..', '..', '..', 'web', 'public', 'uploads', 'inventory',userId.toString() , productId.toString()); + // Crea el directorio si no existe + await mkdir(picturesPath, { recursive: true }); + + await Promise.all(file.map(async (f, index) => { + const fileName = `${index + 1}-${f.originalname}`; + const filePath = join(picturesPath, fileName); + await writeFile(filePath, f.buffer); + })); + return newProduct - }); + }) } - async update(id: string, updateProductDto: UpdateProductDto): Promise { - const productId = parseInt(id); - // console.log(updateProductDto); + // async update(id: string, updateProductDto: UpdateProductDto): Promise { + // const productId = parseInt(id); + // // console.log(updateProductDto); - // Check if exists - await this.findOne(id); + // // Check if exists + // await this.findOne(id); - // Prepare update data - const updateData: any = {}; - if (updateProductDto.title) updateData.title = updateProductDto.title; - if (updateProductDto.description) updateData.description = updateProductDto.description; - if (updateProductDto.price) updateData.price = updateProductDto.price; - if (updateProductDto.address) updateData.address = updateProductDto.address; - if (updateProductDto.status) updateData.status = updateProductDto.status; - if (updateProductDto.stock) updateData.stock = updateProductDto.stock; - if (updateProductDto.urlImg) updateData.urlImg = updateProductDto.urlImg; + // // Prepare update data + // const updateData: any = {}; + // if (updateProductDto.title) updateData.title = updateProductDto.title; + // if (updateProductDto.description) updateData.description = updateProductDto.description; + // if (updateProductDto.price) updateData.price = updateProductDto.price; + // if (updateProductDto.address) updateData.address = updateProductDto.address; + // if (updateProductDto.status) updateData.status = updateProductDto.status; + // if (updateProductDto.stock) updateData.stock = updateProductDto.stock; + // if (updateProductDto.urlImg) updateData.urlImg = updateProductDto.urlImg; - const [updatedProduct] = await this.drizzle.update(products).set(updateData).where(eq(products.id, productId)).returning(); - return updatedProduct - // Return updated user - // return this.findOne(id); - } + // const [updatedProduct] = await this.drizzle.update(products).set(updateData).where(eq(products.id, productId)).returning(); + // return updatedProduct + // // Return updated user + // // return this.findOne(id); + // } /** * Guarda una imagen en el directorio de imágenes. * @param file - El archivo de imagen a guardar. * @returns La ruta de la imagen guardada. */ - async saveImages(file: Express.Multer.File[], updateProductDto: UpdateProductDto, id: number): Promise { - const productId = parseInt(id.toString()); + async saveImages(file: Express.Multer.File[], updateProductDto: UpdateProductDto, userId: number): Promise { + const productId = parseInt(updateProductDto.id); // Construye la ruta al directorio de imágenes. - const picturesPath = join(__dirname, '..', '..', '..', '..', 'web', 'public', 'uploads', 'inventory', id.toString()); + const picturesPath = join(__dirname, '..', '..', '..', '..', 'web', 'public', 'uploads', 'inventory', userId.toString() , productId.toString()); // --- NUEVA LÓGICA: Borrar el directorio anterior --- try { @@ -278,6 +307,7 @@ export class InventoryService { if (updateProductDto.status) updateData.status = updateProductDto.status; if (updateProductDto.stock) updateData.stock = updateProductDto.stock; if (file && file.length > 0) updateData.gallery = gallery; + if (file && file.length > 0) updateData.urlImg = gallery[0]; const [updatedProduct] = await this.drizzle.update(products).set(updateData).where(eq(products.id, productId)).returning(); return updatedProduct; diff --git a/apps/web/app/dashboard/productos/[id]/page.tsx b/apps/web/app/dashboard/productos/[id]/page.tsx index 7e553ab..53ac9bd 100644 --- a/apps/web/app/dashboard/productos/[id]/page.tsx +++ b/apps/web/app/dashboard/productos/[id]/page.tsx @@ -10,8 +10,7 @@ import { CardHeader, CardTitle, } from '@repo/shadcn/card'; -import { Edit } from 'lucide-react'; - +import {ProductList} from '@/feactures/inventory/components/products/see-product' export default async function SurveyResponsePage({ params, @@ -39,56 +38,57 @@ export default async function SurveyResponsePage({ // console.log(data.data); return ( + // -
-
+ //
+ //
- + // -
- -
-
- - - - {product.title.charAt(0).toUpperCase() + product.title.slice(1)} - -

$ {product.price}

- {product.status === 'AGOTADO' ? ( -

AGOTADO

- ) : ('')} -
- -
-

Descripción

-

{product.description}

- {/*

{lorem+lorem+lorem+lorem}

*/} -
+ //
+ // + //
+ //
+ // + // + // + // {product.title.charAt(0).toUpperCase() + product.title.slice(1)} + // + //

$ {product.price}

+ // {product.status === 'AGOTADO' ? ( + //

AGOTADO

+ // ) : ('')} + //
+ // + //
+ //

Descripción

+ //

{product.description}

+ // {/*

{lorem+lorem+lorem+lorem}

*/} + //
-
-

Dirección

-

{product.address}

-
-
+ //
+ //

Dirección

+ //

{product.address}

+ //
+ // - -
-

Información del vendedor

-

{product.fullname}

-

{product.phone}

-

{product.email}

-
-
-
-
+ // + //
+ //

Información del vendedor

+ //

{product.fullname}

+ //

{product.phone}

+ //

{product.email}

+ //
+ //
+ // + // ); } \ No newline at end of file diff --git a/apps/web/feactures/auth/actions/refresh-token-action.ts b/apps/web/feactures/auth/actions/refresh-token-action.ts index 707274b..9d0c4f6 100644 --- a/apps/web/feactures/auth/actions/refresh-token-action.ts +++ b/apps/web/feactures/auth/actions/refresh-token-action.ts @@ -7,14 +7,9 @@ import { export const resfreshTokenAction = async (refreshToken: RefreshTokenValue) => { try { - const body = { - token: refreshToken.token, - } + const response = await refreshApi.patch('/auth/refresh', {refresh_token: refreshToken.token}); - // Usa la nueva instancia `refreshApi` - const response = await refreshApi.patch('/auth/refresh', body); - - const parsed = RefreshTokenResponseSchema.safeParse(response.data); + const parsed = RefreshTokenResponseSchema.safeParse(response.data); if (!parsed.success) { console.error('Error de validación en la respuesta de refresh token:', { diff --git a/apps/web/feactures/inventory/actions/actions.ts b/apps/web/feactures/inventory/actions/actions.ts index d6146f0..960ce53 100644 --- a/apps/web/feactures/inventory/actions/actions.ts +++ b/apps/web/feactures/inventory/actions/actions.ts @@ -118,15 +118,15 @@ export const getProductById = async (id: number) => { }; export const createProductAction = async (payload: FormData) => { - const session = await auth() - const userId = session?.user?.id + // const session = await auth() + // const userId = session?.user?.id - if (userId) { - payload.append('userId', String(userId)); - } + // if (userId) { + // payload.append('userId', String(userId)); + // } const [error, data] = await safeFetchApi( - productMutate, + test, '/products', 'POST', payload, diff --git a/apps/web/feactures/inventory/components/inventory/create-product-form.tsx b/apps/web/feactures/inventory/components/inventory/create-product-form.tsx index d6554c5..a32d05d 100644 --- a/apps/web/feactures/inventory/components/inventory/create-product-form.tsx +++ b/apps/web/feactures/inventory/components/inventory/create-product-form.tsx @@ -18,7 +18,7 @@ import { } from '@repo/shadcn/select'; import { Input } from '@repo/shadcn/input'; import { useForm } from 'react-hook-form'; -import { useCreateUser } from "@/feactures/inventory/hooks/use-mutation"; +import { useCreateProduct } from "@/feactures/inventory/hooks/use-mutation"; import { editInventory, EditInventory } from '@/feactures/inventory/schemas/inventory'; import { Textarea } from '@repo/shadcn/textarea'; import { STATUS } from '@/constants/status' @@ -37,7 +37,7 @@ export function CreateForm({ const { mutate: saveProduct, isPending: isSaving, - } = useCreateUser(); + } = useCreateProduct(); const [sizeFile, setSizeFile] = useState('0 bytes'); const [previewUrls, setPreviewUrls] = useState([]); diff --git a/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx b/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx index a118e96..539fd27 100644 --- a/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx +++ b/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx @@ -14,7 +14,7 @@ export const columns: ColumnDef[] = [ header: 'img', cell: ({ row }) => { return ( - + ) }, }, diff --git a/apps/web/feactures/inventory/components/inventory/update-product-form.tsx b/apps/web/feactures/inventory/components/inventory/update-product-form.tsx index 921645a..d8133e8 100644 --- a/apps/web/feactures/inventory/components/inventory/update-product-form.tsx +++ b/apps/web/feactures/inventory/components/inventory/update-product-form.tsx @@ -18,7 +18,7 @@ import { } from '@repo/shadcn/select'; import { Input } from '@repo/shadcn/input'; import { useForm } from 'react-hook-form'; -import { useUpdateUser } from "@/feactures/inventory/hooks/use-mutation"; +import { useUpdateProduct } from "@/feactures/inventory/hooks/use-mutation"; import { editInventory, EditInventory } from '@/feactures/inventory/schemas/inventory'; // Renombrado EditInventory para claridad import { Textarea } from '@repo/shadcn/components/ui/textarea'; import {STATUS} from '@/constants/status' @@ -55,7 +55,7 @@ export function UpdateForm({ mutate: saveAccountingAccounts, isPending: isSaving, isError, - } = useUpdateUser(); + } = useUpdateProduct(); const [sizeFile, setSizeFile] = useState('0 bytes'); const [previewUrls, setPreviewUrls] = useState([]); @@ -106,10 +106,10 @@ export function UpdateForm({ } } - // --- IMPORTANTE: Tu hook `useUpdateUser` DEBE ser capaz de aceptar FormData --- - // Si `useUpdateUser` llama a `safeFetchApi`, entonces `safeFetchApi` ya está preparado + // --- IMPORTANTE: Tu hook `useUpdateProduct` DEBE ser capaz de aceptar FormData --- + // Si `useUpdateProduct` llama a `safeFetchApi`, entonces `safeFetchApi` ya está preparado // para recibir `FormData`. - saveAccountingAccounts(formData as any, { // Forzamos el tipo a 'any' si `useUpdateUser` no espera FormData en su tipo + saveAccountingAccounts(formData as any, { // Forzamos el tipo a 'any' si `useUpdateProduct` no espera FormData en su tipo onSuccess: () => { form.reset(); onSuccess?.(); diff --git a/apps/web/feactures/inventory/components/products/product-list.tsx b/apps/web/feactures/inventory/components/products/product-list.tsx index ff18790..daab53d 100644 --- a/apps/web/feactures/inventory/components/products/product-list.tsx +++ b/apps/web/feactures/inventory/components/products/product-list.tsx @@ -44,7 +44,7 @@ export function ProductList() { diff --git a/apps/web/feactures/inventory/components/products/see-product.tsx b/apps/web/feactures/inventory/components/products/see-product.tsx new file mode 100644 index 0000000..2340bce --- /dev/null +++ b/apps/web/feactures/inventory/components/products/see-product.tsx @@ -0,0 +1,64 @@ +import { allProducts, } from "../../schemas/inventory"; +import { + Card, + CardContent, + CardFooter, + CardHeader, + CardTitle, +} from '@repo/shadcn/card'; + +export function ProductList({product}: {product: allProducts}) { +return ( + // +
+
+ + + +
+ +
+
+ + + + {product.title.charAt(0).toUpperCase() + product.title.slice(1)} + +

$ {product.price}

+ {product.status === 'AGOTADO' ? ( +

AGOTADO

+ ) : ('')} +
+ +
+

Descripción

+

{product.description}

+ {/*

{lorem+lorem+lorem+lorem}

*/} +
+ +
+

Dirección

+

{product.address}

+
+
+ + +
+

Información del vendedor

+

{product.fullname}

+

{product.phone}

+

{product.email}

+
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/feactures/inventory/hooks/use-mutation.ts b/apps/web/feactures/inventory/hooks/use-mutation.ts index 4cb1053..e5fa84b 100644 --- a/apps/web/feactures/inventory/hooks/use-mutation.ts +++ b/apps/web/feactures/inventory/hooks/use-mutation.ts @@ -3,7 +3,7 @@ import { EditInventory } from "../schemas/inventory"; import { updateUserAction, createProductAction, updateUserAction2 } from "../actions/actions"; // Create mutation -export function useCreateUser() { +export function useCreateProduct() { const queryClient = useQueryClient(); const mutation = useMutation({ mutationFn: (data: any) => createProductAction(data), @@ -13,7 +13,7 @@ export function useCreateUser() { } // Update mutation -export function useUpdateUser() { +export function useUpdateProduct() { const queryClient = useQueryClient(); const mutation = useMutation({ // mutationFn: (data: EditInventory) => updateUserAction(data), diff --git a/apps/web/feactures/inventory/schemas/inventory.ts b/apps/web/feactures/inventory/schemas/inventory.ts index 6048191..094676e 100644 --- a/apps/web/feactures/inventory/schemas/inventory.ts +++ b/apps/web/feactures/inventory/schemas/inventory.ts @@ -1,5 +1,6 @@ // import { user } from '@/feactures/auth/schemas/register'; // import { all } from 'axios'; +import { url } from 'inspector'; import { z } from 'zod'; export type InventoryTable = z.infer; @@ -26,7 +27,11 @@ export const product = z.object({ userId: z.number().optional() }) -export const productDetails = product.extend({ +export const seeProduct = product.extend({ + urlImg: z.string(), +}) + +export const productDetails = seeProduct.extend({ fullname: z.string(), phone: z.string().nullable(), email: z.string().email().nullable() diff --git a/apps/web/lib/auth.config.ts b/apps/web/lib/auth.config.ts index 934894b..23985bb 100644 --- a/apps/web/lib/auth.config.ts +++ b/apps/web/lib/auth.config.ts @@ -100,65 +100,77 @@ const authConfig: NextAuthConfig = { signIn: '/', //sigin page }, callbacks: { - async jwt({ - token, - user, - }: { - token: any; - user: User; + async jwt({ token, user }:{ + user: User + token: any + }) { + // 1. Manejar el inicio de sesión inicial + // El `user` solo se proporciona en el primer inicio de sesión. + if (user) { + return { + id: user.id, + username: user.username, + fullname: user.fullname, + email: user.email, + role: user.role, + access_token: user.access_token, + access_expire_in: user.access_expire_in, + refresh_token: user.refresh_token, + refresh_expire_in: user.refresh_expire_in + } + // return token; + } + + // 2. Si no es un nuevo login, verificar la expiración del token + const now = Math.floor(Date.now() / 1000); // Usar Math.floor para un número entero + + // Verificar si el token de acceso aún es válido + if (now < (token.access_expire_in as number)) { + return token; // Si no ha expirado, no hacer nada y devolver el token actual + } + + console.log("Now Access Expire:",token.access_expire_in); + + + // 3. Si el token de acceso ha expirado, verificar el refresh token + console.log("Access token ha expirado. Verificando refresh token..."); + if (now > (token.refresh_expire_in as number)) { + console.log("Refresh token ha expirado. Forzando logout."); + return null; // Forzar el logout al devolver null + } + + console.log("token:", token.refresh_token); + + + // 4. Si el token de acceso ha expirado pero el refresh token es válido, renovar + console.log("Renovando token de acceso..."); try { - // Si es un nuevo login, asignamos los datos - if (user) { - token.id = user.id; - token.username = user.username; - token.fullname = user.fullname; - token.email = user.email; - token.role = user.role; - token.access_token = user.access_token; - token.access_expire_in = user.access_expire_in; - token.refresh_token = user.refresh_token; - token.refresh_expire_in = user.refresh_expire_in; - return token; // IMPORTANTE: retornamos el token aquí para evitar que entre en el siguiente 'if' + const res = await resfreshTokenAction({ token: token.refresh_token as string }); + + if (!res || !res.tokens) { + throw new Error('Fallo en la respuesta de la API de refresco.'); } - // Verificar si el access_token ha expirado - const now = Date.now() / 1000; - if (now < (token.access_expire_in as number)) { - return token; // Si el token no ha expirado, lo retornamos sin cambios - } + console.log("Old Access Expire:", token.access_expire_in); + console.log("New Access Expire:", res.tokens.access_expire_in); - // Si el access_token ha expirado, verificar el refresh_token - if (now > (token.refresh_expire_in as number)) { - console.log("Refresh token ha expirado. Forzando logout."); - return null; // Forzar logout - } - - // Si el access_token ha expirado pero el refresh_token es válido, renovar - console.log("Renovando token de acceso..."); - const res = await resfreshTokenAction({ - token: token.refresh_token as string, - }); - - console.log("Pepe"); + console.log("token:", token.refresh_token); - if (!res) throw new Error('Fallo al renovar el token'); + // Actualizar el token directamente con los nuevos valores + token.access_token = res.tokens.access_token; + token.access_expire_in = res.tokens.access_expire_in; + token.refresh_token = res.tokens.refresh_token; + token.refresh_expire_in = res.tokens.refresh_expire_in; + return token; - // Actualizar el token con la nueva información - return { - ...token, - access_token: res.tokens.access_token, - access_expire_in: res.tokens.access_expire_in, - refresh_token: res.tokens.refresh_token, - refresh_expire_in: res.tokens.refresh_expire_in, - }; } catch (error) { console.error("Error al renovar el token: ", error); return null; // Fallo al renovar, forzar logout } }, - async session({ session, token }: { session: Session; token: DefaultJWT }) { + async session({ session, token }: { session: Session; token: any }) { session.access_token = token.access_token as string; session.access_expire_in = token.access_expire_in as number; session.refresh_token = token.refresh_token as string; diff --git a/apps/web/lib/fetch.api.ts b/apps/web/lib/fetch.api.ts index 39a6212..56681e3 100644 --- a/apps/web/lib/fetch.api.ts +++ b/apps/web/lib/fetch.api.ts @@ -12,6 +12,8 @@ const fetchApi = axios.create({ // ESTE INTERCEPTOR ESTÁ BIEN PARA EL RESTO DE LAS PETICIONES AUTENTICADAS fetchApi.interceptors.request.use(async (config: any) => { try { + console.log("Solicitando autenticación..."); + const { auth } = await import('@/lib/auth'); // Importación dinámica const session = await auth(); const token = session?.access_token; diff --git a/apps/web/public/uploads/inventory/1/1-ibuki-douji-sign-noise-sd.jpg b/apps/web/public/uploads/inventory/1/1-ibuki-douji-sign-noise-sd.jpg deleted file mode 100644 index 0dd96ce..0000000 Binary files a/apps/web/public/uploads/inventory/1/1-ibuki-douji-sign-noise-sd.jpg and /dev/null differ diff --git a/apps/web/public/uploads/inventory/1/1/1-17102590731691.jpg b/apps/web/public/uploads/inventory/1/1/1-17102590731691.jpg new file mode 100644 index 0000000..a6d0c54 Binary files /dev/null and b/apps/web/public/uploads/inventory/1/1/1-17102590731691.jpg differ diff --git a/apps/web/public/uploads/inventory/1/1/2-MANZNA-ROJA.jpg b/apps/web/public/uploads/inventory/1/1/2-MANZNA-ROJA.jpg new file mode 100644 index 0000000..b24c76f Binary files /dev/null and b/apps/web/public/uploads/inventory/1/1/2-MANZNA-ROJA.jpg differ diff --git a/apps/web/public/uploads/inventory/1/7/1-D_NQ_NP_989621-MLV81067179982_122024-O.webp b/apps/web/public/uploads/inventory/1/7/1-D_NQ_NP_989621-MLV81067179982_122024-O.webp new file mode 100644 index 0000000..5f45489 Binary files /dev/null and b/apps/web/public/uploads/inventory/1/7/1-D_NQ_NP_989621-MLV81067179982_122024-O.webp differ