Laravel Sanctum

Source Code

Laravel Sanctum provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token based APIs. Sanctum allows each user of your application to generate multiple API tokens for their account. These tokens may be granted abilities / scopes which specify which actions the tokens are allowed to perform. (Read More)

Usage

auth: {
  strategies: {
    laravelSanctum: {
      provider: 'laravel/sanctum',
      url: '<laravel url>'
    },
  }
}

NOTE: It is highly recommended to use proxy to avoid CORS and same-site policy issues:

{
  axios: {
    proxy: true,
    credentials: true
  },
  proxy: {
    '/laravel': {
      target: 'https://laravel-auth.nuxtjs.app',
      pathRewrite: { '^/laravel': '/' }
    }
  },
  auth: {
    strategies: {
      laravelSanctum: {
        provider: 'laravel/sanctum',
        url: '<laravel url>'
      }
    }
  }
}

To login user:

this.$auth.loginWith('laravelSanctum', {
  data: {
    email: '',
    password: ''
  }
})

💁 This provider is based on cookie scheme and supports all scheme options.

Edit this page on GitHub Updated at Thu, Oct 5, 2023