2.0.0 • Published 5 years ago

@z1lab/auth v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

auth

Introduction

Module developed for the nuxt framework for app authentication and user management.

License

Auth Modulo is open source software licensed under the MIT License.

Installation

yarn add @z1lab/auth or npm install @z1lab/auth

Setup

Edit nuxt.config.js:

modules: [
  '@nuxtjs/axios',
  '@nuxtjs/auth'
],

auth: {
  // Options
}

Important

Don't forget to enable vuex store in your app. More information on how to do that can be found on the Nuxt Getting Started Guide.

Middleware

You can enable auth middleware either globally or per route. When this middleware is enabled on a route and loggedIn is false user will be redirected to redirect.login route. (/login by default)

Setting per route:

export default {
  middleware: 'auth'
}

Globally setting in nuxt.config.js:

router: {
  middleware: ['auth']
}

In case of global usage, You can set auth option to false in a specific component and the middleware will ignore that route.

export default {
  auth: false
}

You can set auth option to guest in a specific component. When this middleware is enabled on a route and loggedIn is true user will be redirected to redirect.home route. (/ by default)

export default {
  auth: 'guest'
}

Properties

PropertyInputDefaultDescription
resetOnErrorBool/FuncFALSEIf enabled, user will be automatically logged out if an error happens. (For example when token expired).
scopeKeyStringscopeUser object property used for scope checking (hasScope). Can be either an array or a object.
rewriteRedirectsBoolTRUEIf enabled, user will redirect back to the original guarded route instead of redirect.home.
fullPathRedirectBoolFALSEIf true, use the full route path with query parameters for redirect.
watchLoggedInBoolTRUEWhen enabled (default) user will be redirected on login/logouts.
redirectObject{login: '/login', logout: '/', home: '/', callback: '/login'}Routes to redirect after performing certain actions.
vuexObject{namespace: 'auth'}Vuex store namespace.
cookieObject{prefix: 'auth.', options: {path: '/'}}cookie setting options to be set by the plugin.
tokenObject{prefix: 'token.'}Token prefix setting.
id_tokenObject{prefix: 'id_token.'}Token prefix setting.
refresh_tokenObject{prefix: 'refresh_token.'}Token prefix setting.
defaultStrategyBoolundefinedDefault strategy name.
strategiesObject{passport: {url: 'http://api', client_id: '', client_secret: ''}}Etrategies and their settings.

Usage

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

this.$auth.loginWith('passport', {username: 'your_username',password: 'your_password'})

Example config nuxt.config.js:

auth: {
    cookie: {prefix: 'auth2.', options: {path: '/'}},
    strategies: {
      passport: {
        url: 'http://api.com.br',
        client_id: '',
        client_secret: ''
      }
    }
  }
2.0.0

5 years ago

1.6.1-rc3

5 years ago

1.6.1-rc2

5 years ago

1.6.1-rc1

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago