auth cookie
How can I authenticate my nuxt3 app against spring boot 3 app, java app uses JSESSIONID cookie to track sessions. I need to authenticate and then somehow include this cookie to all subsequent requests + protect pages with midleware.
4 Replies
You'll probably be interested in the useCookie composable : https://nuxt.com/docs/api/composables/use-cookie
Pretty good, but this will require you to write some middleware in your nuxt app to handle it correctly (redirection and more).
From my experience, this is a bit harsh to configure (as their is still no magic
nuxt-auth
module for Nuxt3).
Here is the kind of middleware I used. But things can change depending on how you are rendering your pages, what type of cookie you use,...
Also here is how my Nuxt App is defining the cookie in the API (I use Nuxt as a backend) :
This is some Nuxt gymnastic to learn at the moment, but the in coming nuxt-auth
official package will probably do some incredible black magic and cool DX.
It should be released this year I think.https://gist.github.com/silvesterwali/4c4a415e9e76dc666bb01cbaf510d082 here is my composable maybe will help you if you not working with server at all.
Gist
Composable for Nuxt3 for handle simple auth
Composable for Nuxt3 for handle simple auth . GitHub Gist: instantly share code, notes, and snippets.
Thank you. I will try to apply a similar approach in my project. I really hope that the Nuxt team will make nuxt-auth as soon as possible.
Yup, this is clearly something missing for a lot of people (that's why it is pretty much the next official module on the roadmap)