Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
Forma correcta de usar la autenticación de credenciales en next.js/next-auth.js

Estoy tratando de implementar correctamente una autenticación con next.js/next-auth.js. Siguiendo la documentación implementé la autenticación de proveedores. El siguiente código llama a mi api (en php), la api devuelve un token y el token se almacena en una cookie httpOnly.

 import NextAuth from "next-auth" import Providers from "next-auth/providers"; const https = require('https'); export default NextAuth({ providers: [ Providers.Credentials({ name: 'Credentials', credentials: { email: { label: "Email", type: "email" }, password: { label: "Password", type: "password" } }, async authorize(credentials) { const url = process.env.NEXT_PUBLIC_API_PLATFORM_BASE_URL + '/auth'; const httpsAgent = new https.Agent({ rejectUnauthorized: false, }); const response = await fetch(url, { method: 'POST', body: JSON.stringify(credentials), agent: httpsAgent, headers: { "Content-Type": "application/json" } }) const user = await response.json(); if (response.ok && user) { return user; } else { return null; } } }), // ...add more providers here ], callbacks: { async jwt(token, user, account, profile, isNewUser) { if (user?.token) { token = { accessToken: user.token }; } return token; }, async session(session, token) { session.accessToken = token.accessToken; return session; } } })

Necesitaría saber cómo recuperar el token jwt en la cookie httpOnly para futuras llamadas (típicamente pasándolo a la API como Bearer <MYTOKEN> , usando fetch ), pero sé que JS no tiene acceso a las cookies httpOnly. En ese caso, ¿cuál es la mejor manera de proceder?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!