Atinux / nuxt-auth-utils

Minimal Auth module for Nuxt 3.
MIT License
608 stars 58 forks source link

Is Laravel Sanctum as a Provider on the roadmap? #10

Open Skylercrane23 opened 8 months ago

Skylercrane23 commented 8 months ago

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!

Atinux commented 8 months ago

Hey, have you check https://github.com/dystcz/nuxt-sanctum-auth ?

Skylercrane23 commented 8 months ago

I think I saw this one before but doesn't have full SSR support :(

nhedger commented 7 months ago

@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.

MarJose123 commented 1 month ago

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()