Open Skylercrane23 opened 8 months ago
Hey, have you check https://github.com/dystcz/nuxt-sanctum-auth ?
I think I saw this one before but doesn't have full SSR support :(
@Skylercrane23, let me shamelessly plug my own module, which handles SSR:
https://github.com/nhedger/nuxt-sanctum
Still ironing things out, and early feedback would be appreciated.
I'm using Laravel Sanctum and here what I did to make it work.
I've created a signin.post.ts
file in server/api/auth
and I used the setUserSession
utils.
await setUserSession(event, {
user: {
...loginResponse?.user
},
loggedInAt: new Date()
// Any extra fields
})
return {status: 200, success: true}
and on my login page logic
const login = await $fetch("/api/auth/signin",{
method: 'POST',
body: JSON.stringify({
email: data?.email,
password: data?.password,
}),
headers: {
'Content-Type': 'application/json',
}.catch((resp) => console.log(resp))
if(login?.status === 200 && login?.success){
window.location.href = '/login'
}
On your page, you can now retrieve the user session using the composable util
const { loggedIn, user, session, clear } = useUserSession()
Was curious if Laravel Sanctum is on the roadmap to becoming a provider. I currently use Nuxt Auth for my Nuxt2 Applications and really enjoyed how simple that was to get Laravel Sanctum working with. Have recently started several new Nuxt3 projects with a Laravel backend.
Any info would be great, Thanks!