nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

401 error when using cookies and not token #550

Closed radudiaconu0 closed 3 years ago

radudiaconu0 commented 4 years ago

WHen i use laravel airlock with nuxt js and auth module on every page i navigate i get 401 error without being authenticated. i put correct middleware on every route. why is that happen? when i login all things works properly.(i use spa mode but i am curious how can i make things works on unversal mode) this is my nuxt configuration:

axios: { baseURL: 'http://app.cheer.test/', withCredentials: true }, auth: { redirect: { login: '/login', logout: '/', callback: '/login', home: '/home' }, strategies: { local: { endpoints: { login: { url: 'login', method: 'post', withCredentials: true, headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/json' } }, logout: { url: 'logout', method: 'post', withCredentials: true, }, user: { url: '/api/user', method: 'get', propertyName: 'user', withCredentials: true, headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/json' } }, home: '/home' }, tokenRequired: false, tokenType: false } } },

AndrewSavetchuk commented 4 years ago

Same here! Nuxt auth for some reason tries to fetch user when I'm browsing the website as a guest 🤔

Here's my config:

Screen Shot 2020-03-13 at 3 05 12 AM
tiran133 commented 4 years ago

Have a look at this might help you with the solution https://serversideup.net/using-laravel-airlock-with-nuxtjs/

dloused commented 4 years ago

same here...

Nuxt auth for some reason tries to fetch user when I'm browsing the website as a guest 🤔

bruceparish commented 4 years ago

I'm having the same issue as well. There has to be a better way to see if user is logged in on cookie flow that doesn't involve getting a 401 from the user endpoint. And with the user endpoint set to false, you're always logged in. Seems like getting the logged in status in general for the cookie flow is a little off.

ryzexsp commented 4 years ago

same here ...

any solution ?

======

set user to false and get user manually

  axios: {
    baseURL: 'http://127.0.0.1:8000',
    credentials : true
  },

  auth: {
    strategies: {
      local: {
        endpoints: {
          login: {
            url: '/login',
            method: 'post',
          },
          user: false
        },
        tokenRequired: false,
        tokenType: false
      }
    }
  },
pawel-marciniak commented 4 years ago

Same issue here... Can this be even fixed?

planetchili commented 3 years ago

Yeah, it seems pretty broken. Glad it's not just me. Disabling the feature altogether and grabbing that data manually seems like a viable workaround at least.

JoaoPedroAS51 commented 3 years ago

Closing here, as cookie scheme and laravel sanctum provider are now available in auth v5.

GanchoDanailov commented 3 years ago

any update on this?

JoaoPedroAS51 commented 3 years ago

@GanchoDanailov @planetchili @pawel-marciniak @ryzexsp @brcpar @dloused @tiran133 @AndrewSavetchuk

Hey guys! This issue was already fixed :)

You should use cookie scheme, which depends on cookie instead of token. And if you are using laravel sanctum, then I recommend the laravel sanctum provider.

Both are available in auth v5. We now recommend using v5 instead of v4. See status and #893