Nuxt 3 Authentication with Laravel 9 and Sanctum
Asked Answered
Q

2

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

Quaternion answered 25/11, 2022 at 10:34 Comment(1)
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.Angilaangina
C
2

I found a great article for how to setup authentication with Laravel Sanctum and Nuxt 3 with SSR here:

https://manchenkoff.medium.com/laravel-10-and-nuxt-3-setup-ssr-with-authentication-from-scratch-497ab1a3fc56

The author later released his solution as an npm package:

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

Chicky answered 5/10, 2023 at 11:14 Comment(0)
D
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.

Decaliter answered 26/1, 2023 at 16:46 Comment(2)
I have found this [github.com/amrnn90/breeze-nuxt], will create time to test both implementation and adviceKidder
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.Radiophotograph

© 2022 - 2024 — McMap. All rights reserved.