Auth-module: Confusion about the initial setup

Created on 4 Mar 2021  ·  2Comments  ·  Source: nuxt-community/auth-module

I can't get this plugin works by following the configuration steps mentioned in the docs. I also confused with target in proxy and url at the very bottom.

It took me 3 hours scratching my head, re-reading the docs over and over again trying to grasp what to put where and why it doesn't work. Can anyone please help me with this? Thanks in advance.

{
  axios: {
    proxy: true,
    credentials: true
  },
  proxy: {
     // here, the original was "/laravel", i was ambigued with <laravel url> in the `url` at the very bottom
     // so I changed this to "/foo"
    '/foo': {

      // "laravel-auth.nuxtjs" is once again ambiguous for me, should it be <nuxt> or <laravel>?
      // like, my nuxt endpoint is "http://localhost:3000"
      // and my laravel endpoint is "http:// localhost:8000"
      // which one should I put?
      target: 'https://laravel-auth.nuxtjs.app',

      pathRewrite: { '^/foo': '/' }
    }
  },
  auth: {
    strategies: {
      'laravelSanctum': {
        provider: 'laravel/sanctum',

        // I put "localhost:8000" here and got 404 with "http://localhost:3000/localhost:8000/laravel/sanctum/csrf-cookie"
        // And when I put "/foo" here, also 404, with "http://localhost:3000/foo/foo/sanctum/csrf-cookie"
        // And when I put nothing, this shows me an error page.
        url: '<laravel url>'
      }
    }
  }
}
Nuxt @ v2.15.2

▸ Environment: development
▸ Rendering:   server-side
▸ Target:      server

Listening: http://localhost:3000/
Tailwind Viewer: http://localhost:3000/_tailwind/   
$ php artisan serve
Starting Laravel development server: http://127.0.0.1:8000
[Thu Mar  4 10:11:20 2021] PHP 8.0.1 Development Server (http://127.0.0.1:8000) started
question

Most helpful comment

Hi @pratamatama! I believe this is the config you want:

{
  axios: {
    proxy: true,
    credentials: true
  },
  proxy: {
    // This is the url that nuxt will use to access laravel
    '/foo': {

      // This is the laravel url, in this case, http://localhost:8000
      target: 'http://localhost:8000',

      pathRewrite: { '^/foo': '/' }
    }
  },
  auth: {
    strategies: {
      laravelSanctum: {
       // This provider is probably outdated. You can remove this line or change to laravelSanctum. (If the strategy and provider has the same name, the provider will be automatically detected)
       // provider: 'laravelSanctum',

        // Here should be the url that nuxt will use to access laravel, in this case, /foo
        url: '/foo'
      }
    }
  }
}

We're aware that there are some outdated info in docs and we will be fixing it soon. I'm sorry for the inconvenience.

All 2 comments

Hi @pratamatama! I believe this is the config you want:

{
  axios: {
    proxy: true,
    credentials: true
  },
  proxy: {
    // This is the url that nuxt will use to access laravel
    '/foo': {

      // This is the laravel url, in this case, http://localhost:8000
      target: 'http://localhost:8000',

      pathRewrite: { '^/foo': '/' }
    }
  },
  auth: {
    strategies: {
      laravelSanctum: {
       // This provider is probably outdated. You can remove this line or change to laravelSanctum. (If the strategy and provider has the same name, the provider will be automatically detected)
       // provider: 'laravelSanctum',

        // Here should be the url that nuxt will use to access laravel, in this case, /foo
        url: '/foo'
      }
    }
  }
}

We're aware that there are some outdated info in docs and we will be fixing it soon. I'm sorry for the inconvenience.

Hi @JoaoPedroAS51 ,thanks a lot for helping me out, it works now.. 😁😁
I'm closing the issue.

Was this page helpful?
0 / 5 - 0 ratings