8

I'm using nuxt 3 for a project and can't find an easy way to do authentication with Laravel and Sanctum.

The @nuxtjs/axios module is only compatible for nuxt 2 and the package a developer provided for nuxt 3 (@nuxtjs-alt/auth) doesn't provide much documentation. I tried to implement it but nuxtApp().$auth always returns undefined.

How can I authenticate my user in the Login screen and then have an auth middleware to secure my routes? I reiterate the use of NUXT3

Giampy71
  • 137
  • 1
  • 5
  • You can use cookies to store auth token, get it at a server plugin , store it at a central state so that you can access it everywhere both in ssr and front end.After that you want to create a middleware that checks whether the token is present in the central store and of course deny or allow the requested route. – lwin moe hein Nov 28 '22 at 10:17

1 Answers1

0

Just found this Nuxt 3 sanctum package on GitHub:

https://github.com/dystcz/nuxt-sanctum-auth

Seems like a solution until the official auth module is published for nuxt3.

  • 1
    I have found this [https://github.com/amrnn90/breeze-nuxt], will create time to test both implementation and advice – levis Jan 26 '23 at 22:15
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 03 '23 at 15:47