Auth Module
1.0.0
1.0.0
  • README
  • docs
    • providers
      • GitHub
      • Google
      • Auth0
      • Laravel Passport
      • Facebook
    • Auth Module
    • Migration Guide
    • guide
      • Middleware
      • Providers
      • Setup
      • Schemes
    • recipes
      • Extending Auth plugin
    • api
      • API
      • options
      • storage
      • auth
    • schemes
      • Local
      • Oauth2
    • glossary
  • .github
    • ISSUE_TEMPLATE
  • CHANGELOG
Powered by GitBook
On this page
  • Usage
  • Options
  • endpoints
  • tokenRequired
  • tokenName
  • tokenType
  1. docs
  2. schemes

Local

PreviousschemesNextOauth2

Last updated 5 years ago

local is the default, general purpose authentication scheme, supporting Cookie and JWT login flows.

By default local scheme is enabled and preconfigured. You can set strategies.local to false to disable it.

Usage

To do a password based login by sending credentials in request body as a JSON object:

<template>
  <div>
    <form @submit="userLogin">
      <div>
        <label>Username</label>
        <input type="text" v-model="login.username" />
      </div>
      <div>
        <label>Password</label>
        <input type="text" v-model="login.password" />
      </div>
      <div>
        <button type="submit">Submit</button>
      </div>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      login: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    async userLogin() {
      try {
        let response = await this.$auth.loginWith('local', { data: this.login })
        console.log(response)
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

Options

Example for a token based flow:

auth: {
  strategies: {
    local: {
      endpoints: {
        login: { url: '/api/auth/login', method: 'post', propertyName: 'token' },
        logout: { url: '/api/auth/logout', method: 'post' },
        user: { url: '/api/auth/user', method: 'get', propertyName: 'user' }
      },
      // tokenRequired: true,
      // tokenType: 'bearer'
      // autoFetchUser: true
    }
  }
}

Example for a cookie based flow:

auth: {
  strategies: {
    local: {
      endpoints: {
        login: { url: '/api/auth/login', method: 'post' },
      },
      tokenRequired: false,
      tokenType: false
    }
  }
}

endpoints

::: tip To disable each endpoint, simply set its value to false. :::

propertyName

propertyName can be used to specify which field of the response JSON to be used for value. It can be false to directly use API response or being more complicated like auth.user.

tokenRequired

This option can be used to disable all token handling. Useful for Cookie only flows. (Enabled by default)

tokenName

  • Default: Authorization

    Authorization header name to be used in axios requests.

tokenType

  • Default: Bearer

    Authorization header type to be used in axios requests.

    autoFetchUser

    • Default: true

    This option can be used to disable user fetch after login.

Each endpoint is used to make requests using axios. They are basically extending Axios .

TIP: It is useful when your login response already have the user. To manually set the user, use .

Source Code
Request Config
setUser