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

173
Views
How to use a JWT token inside an httpOnly cookie to call a restricted api endpoint

I am using next.js and next-auth to login users against an API. if the login is successful, an httpOnly cookie is set to the browser. The cookie name is __Secure-next-auth.session-token and this is the value (no worries is fake data):

eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6ImV5SjBlWEFpT2lKS1YxUWlMQ0poYkdjaU9pSlNVekkxTmlKOS5leUpwWVhRaU9qRTJNelkyTXprMk5EY3NJbVY0Y0NJNk1UWXpOalkwTXpJME55d2ljbTlzWlhNaU9sc2lVazlNUlY5VlUwVlNJbDBzSW5WelpYSnVZVzFsSWpvaVpYSnVZVE01UUhkbFltVnlMbU52YlNKOS5obWZqQ3NBWDFsWHdCMWdUNDlRUFdRWjM4OG52b2pKTlJMaDI1d3RCTVlBSHhQN2RxelpsZWFzTWZSVXZqSmJXVjdRUldYZnRYYUJFOG1pTEE4Y1JsNTVlZUd5bE9MbHhoQVRORTZPNjZLQjdzMXhPczB6Nmg1TXFadnlRa3JhcjFfYnF5WXgzQzBZdXVHWk1NWEFMUDJPS3Q5Sjk2dVdZVF9KT25USzNhRTZEQnpqaWF5OWw2alludExLZkUyQUhKMVgwVE9UcEN3QjBHeFB3d1otVWh0NjU5NEtLZS0yakpkQmhqd185VGJWSUVFaV9SbF8zMDFabmhHdDZZYzN6SE9WNm9WSk4zOTBSTXFrM283cWRONkw0R0JKb1g5NzQ1NkNJLTVFSllJN3ozcXpjVEwtZUNGc3luRkJIZHEzNnF2TFd3aDJpeDVkTy1MVDU1cXE5VlEiLCJpYXQiOjE2MzY2NTcwNjYsImV4cCI6MTYzOTI0OTA2Nn0.QGRPwJSECbFfkvUyn8h-gInELUzGHsxBFrnMAW9zEfqCuHwJRkT1aunqFt7g5aWp6DZrSUHaKvp3OJr-0xwUzw

if I decode this jwt, I get an object where one of the properties is jwt and the value is the token I received from the API.

Can anyone please tell me

  • if this is the correct format and
  • how can I use it in a fetch call to restricted api endpoints?

At the monent I am just doing a fetch call with this options

    method: 'GET',
    'cors': 'no-cors',
    credentials: 'same-origin'

but no luck the response I get is

 [Symbol(Response internals)]: {
    url: 'https://localhost/countries',
    status: 401,
    statusText: 'Unauthorized',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You'll need to check your API documentation to see what it's expecting. Often, for example, you'll attach the token to the Authorization header

about 4 years ago · Juan Pablo Isaza Report
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!