authjs-nuxt icon indicating copy to clipboard operation
authjs-nuxt copied to clipboard

fix: getServerToken returns null when used in middleware

Open Niki2k1 opened this issue 2 years ago โ€ข 5 comments

๐Ÿ”— Linked issue

#139

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • [x] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [ ] ๐Ÿ‘Œ Enhancement (improving an existing functionality like performance)
  • [ ] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

When using getServerToken in a middleware the function returns null because it can't read the cookies. I changed your cookie parsing from the headers to using the h3 function parseCookies

Resolves #139

๐Ÿ“ Checklist

  • [x] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

Niki2k1 avatar Dec 27 '23 13:12 Niki2k1

Was there a reason you parsed the cookies yourself instead of using the h3 parseCookies function?

Niki2k1 avatar Dec 27 '23 13:12 Niki2k1

Was there a reason you parsed the cookies yourself instead of using the h3 parseCookies function?

It wasn't implemented properly in h3 when I created the module, but pretty sure it got fixed now.

Hebilicious avatar Dec 28 '23 09:12 Hebilicious

The fix look good, but I need to find the time to test it as we don't have good test coverage set-up.

Hebilicious avatar Jan 04 '24 00:01 Hebilicious

I would like to add that this does not solve getServerToken returning null on the server. Is there a workaround for getting the user's id?

ferat avatar Feb 21 '24 03:02 ferat

@ferat Could you give #167 a try ? I believe this will resolve the issue and we'll close this PR.

Hebilicious avatar Feb 21 '24 15:02 Hebilicious