Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nuxtjs/auth

Package Overview
Dependencies
Maintainers
4
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/auth - npm Package Compare versions

Comparing version 4.0.0-rc.3 to 4.0.0

lib/auth/auth.js

42

CHANGELOG.md

@@ -5,2 +5,38 @@ # Change Log

<a name="4.0.0"></a>
# [4.0.0](https://github.com/nuxt-community/auth-module/compare/v4.0.0-rc.3...v4.0.0) (2018-04-02)
### Bug Fixes
* clear axios token after logout ([#84](https://github.com/nuxt-community/auth-module/issues/84)) ([be65f09](https://github.com/nuxt-community/auth-module/commit/be65f09))
* Typo in README.md ([1ec0882](https://github.com/nuxt-community/auth-module/commit/1ec0882))
* use getToken ([bec8518](https://github.com/nuxt-community/auth-module/commit/bec8518))
* wrong axios ordering in windows platform. ([#56](https://github.com/nuxt-community/auth-module/issues/56)) ([44db0d4](https://github.com/nuxt-community/auth-module/commit/44db0d4))
* **auth:** return promise reject on request error ([f2883c6](https://github.com/nuxt-community/auth-module/commit/f2883c6))
* **fetchUser:** fetchUser should only be called when enabled ([dd0638e](https://github.com/nuxt-community/auth-module/commit/dd0638e))
* **fetchUser:** fetchUser should only be called when enabled ([#60](https://github.com/nuxt-community/auth-module/issues/60)) ([beb3121](https://github.com/nuxt-community/auth-module/commit/beb3121))
* **module:** remove duplicate strategy options ([2e167f8](https://github.com/nuxt-community/auth-module/commit/2e167f8))
### Features
* add auth0-js scheme ([c38a1e4](https://github.com/nuxt-community/auth-module/commit/c38a1e4))
* **package:** add client-oauth2 ([e0efa60](https://github.com/nuxt-community/auth-module/commit/e0efa60))
* **redirect:** add full path redirect option ([#96](https://github.com/nuxt-community/auth-module/issues/96)) ([ca8785f](https://github.com/nuxt-community/auth-module/commit/ca8785f))
* allow extending auth with plugins ([#98](https://github.com/nuxt-community/auth-module/issues/98)) ([3712a60](https://github.com/nuxt-community/auth-module/commit/3712a60))
* allow providers params to be overloaded from nuxt.config.js ([#77](https://github.com/nuxt-community/auth-module/issues/77)) ([8542959](https://github.com/nuxt-community/auth-module/commit/8542959))
* handle invalid strategy ([f079ae2](https://github.com/nuxt-community/auth-module/commit/f079ae2))
* loginWith function ([2aed448](https://github.com/nuxt-community/auth-module/commit/2aed448))
* **test:** add custom _provider and _scheme for basic fixture ([7423e77](https://github.com/nuxt-community/auth-module/commit/7423e77))
* use consola for cli messages ([1db2b2e](https://github.com/nuxt-community/auth-module/commit/1db2b2e))
* user and loggedIn shortcuts ([13a5eec](https://github.com/nuxt-community/auth-module/commit/13a5eec))
### Performance Improvements
* **module:** optimize plugin ([b7998c6](https://github.com/nuxt-community/auth-module/commit/b7998c6))
<a name="4.0.0-rc.3"></a>

@@ -87,3 +123,3 @@ # [4.0.0-rc.3](https://github.com/nuxt-community/auth-module/compare/v4.0.0-rc.2...v4.0.0-rc.3) (2018-02-04)

* rc11 backward compability ([c0222e9](https://github.com/nuxt-community/auth-module/commit/c0222e9))
* rc11 backward compatibility ([c0222e9](https://github.com/nuxt-community/auth-module/commit/c0222e9))

@@ -103,3 +139,3 @@

* improve compability for nuxt 1.0.0 ([7740dec](https://github.com/nuxt-community/auth-module/commit/7740dec))
* improve compatibility for nuxt 1.0.0 ([7740dec](https://github.com/nuxt-community/auth-module/commit/7740dec))

@@ -116,3 +152,3 @@

* allow customizing http method for user endpoint ([#28](https://github.com/nuxt-community/auth-module/issues/28)) ([994152b](https://github.com/nuxt-community/auth-module/commit/994152b))
* more compability for nuxt@next ([d50be11](https://github.com/nuxt-community/auth-module/commit/d50be11))
* more compatibility for nuxt@next ([d50be11](https://github.com/nuxt-community/auth-module/commit/d50be11))

@@ -119,0 +155,0 @@

48

package.json
{
"name": "@nuxtjs/auth",
"version": "4.0.0-rc.3",
"version": "4.0.0",
"description": "Authentication module for Nuxt.js",

@@ -19,3 +19,3 @@ "license": "MIT",

],
"main": "lib/module.js",
"main": "lib/module/index.js",
"repository": "https://github.com/nuxt-community/auth-module",

@@ -26,5 +26,5 @@ "publishConfig": {

"scripts": {
"heroku-postbuild": "nuxt build example",
"start": "nuxt start example",
"dev": "nuxt example",
"heroku-postbuild": "nuxt build examples/demo",
"start": "nuxt start examples/demo",
"dev": "nuxt examples/demo",
"lint": "eslint lib src test",

@@ -36,3 +36,3 @@ "lint-fix": "eslint --fix lib src test",

"eslintIgnore": [
"**/templates/**"
"lib/module/plugin.js"
],

@@ -47,3 +47,5 @@ "files": [

"dependencies": {
"@nuxtjs/axios": "^5.0.0-rc.2",
"@nuxtjs/axios": "^5.3.1",
"boom": "^7.2.0",
"consola": "^1.2.0",
"cookie": "^0.3.1",

@@ -55,22 +57,26 @@ "dotprop": "^1.0.2",

"devDependencies": {
"@nuxtjs/toast": "^3.0.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"body-parser": "^1.18.2",
"bootstrap-vue": "^2.0.0-rc.1",
"bootstrap-vue": "^2.0.0-rc.4",
"codecov": "latest",
"cookie-parser": "^1.4.3",
"eslint": "latest",
"eslint-config-standard": "latest",
"eslint-plugin-import": "latest",
"eslint-plugin-jest": "latest",
"eslint-plugin-node": "latest",
"eslint-plugin-promise": "latest",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-jest": "^21.15.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "latest",
"eslint-plugin-vue": "latest",
"express": "latest",
"express-jwt": "^5.3.0",
"jest": "latest",
"jsdom": "latest",
"nuxt": "latest",
"puppeteer": "^1.0.0",
"eslint-plugin-vue": "^4.4.0",
"express": "^4.16.3",
"express-jwt": "^5.3.1",
"jest": "^22.4.3",
"jsdom": "^11.7.0",
"nuxt-class-component": "^1.2.0",
"nuxt-edge": "^2.0.0-25377845.e2e124b",
"puppeteer": "^1.2.0",
"standard-version": "latest"
}
}

@@ -1,5 +0,6 @@

<h1 align="center">🔑 Auth</h1>
# 🔑 Auth Module
<p align="center">Authentication module for Nuxt.js</p>
> Authentication module for Nuxt.js
<p align="center">

@@ -27,258 +28,13 @@ <a href="https://david-dm.org/nuxt-community/auth-module">

[📖 **Release Notes**](./CHANGELOG.md)
📖 [**Read Documentation**](https://auth.nuxtjs.org)
If you are coming from an older release please be sure to read [Migration Guide](https://github.com/nuxt-community/auth-module/wiki/Migration-guide).
**Running demo for development:**
<h2 align="center">Setup</h2>
Install with yarn:
```bash
yarn add @nuxtjs/auth @nuxtjs/axios
$ yarn install
$ yarn dev
```
Install with npm:
## 📑 License
```bash
npm install @nuxtjs/auth @nuxtjs/axios
```
Edit `nuxt.config.js`:
```js
{
modules: [
'@nuxtjs/axios',
'@nuxtjs/auth'
],
auth: {
// Options
}
```
See [Options](#options) section for all available options
<h2 align="center">Usage</h2>
Do a password based login:
```js
this.$auth.login({
data: {
username: 'your_username',
password: 'your_password'
}
})
```
`user` object:
```js
// Access using $auth (reactive)
this.$auth.state.user
// Access using $store (reactive)
this.$store.state.auth.user
// Refetch user
this.$auth.fetchUser()
```
`loggedIn` status:
```js
// Access using $auth (reactive)
this.$auth.state.loggedIn
// Access using $store (reactive)
this.$store.state.auth.loggedIn
// Do logout
this.$auth.logout()
```
Check if user has a speficic scope:
```js
// Returns is a computed boolean
this.$auth.hasScope('admin')
```
Auth token:
```js
// Access token (reactive)
this.$auth.token
// Update token
this.$auth.setToken('123')
```
Listen for auth errors: (`plugins/auth.js`)
```js
export default function({ $auth }) {
$auth.onError((error, name, endpoint) => {
console.error(name, error)
})
}
```
Working with low level state: (Not recommended)
```js
// Store
this.$auth.setState(key, val)
this.$auth.getState(key)
// Watch state changes
this.$auth.watchState('loggedIn', newValue => { })
// Cookie
this.$auth.setCookie(key, val, options)
this.$auth.getCookie(key)
// LocalStorage
this.$auth.setLocalstorage(key, val, options)
this.$auth.getLocalstorage(key)
```
<h2 align="center">Auth Middleware</h2>
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:
```js
export default {
middleware: 'auth'
}
```
Globally setting in `nuxt.config.js`:
```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.
```js
export default {
auth: false
}
```
<h2 align="center">Options</h2>
See [defaults.js](lib/defaults.js) for defaults.
### `endpoints`
Default:
```js
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' }
}
```
Endpoints used to make requests using axios. They are basically extending Axios [Request Config](https://github.com/axios/axios#request-config).
`propertyName` can be used to specify which field of the response to be used for value. It can be `undefined` to directly use API response or being more complicated like `auth.user`.
To disable each endpoint, simply set it's value to `false`.
### `redirect`
Default:
```js
redirect: {
login: '/login',
home: '/'
},
```
Redirect paths to redirect user after login and logout. Each can be disabled by setting to `false`.
### `token`
Default:
```js
token: {
type: 'Bearer',
name: 'token'.
}
```
* **type** - Authotization header type to be used in axios requests.
* **name** - Token name to be stored in Browser localStorage. It can be disabled by setting to `false`.
### `cookie`
Default:
```js
cookie: {
name: 'token',
options: {
path: '/'
}
}
```
Using cookies is **required** for SSR requests to work with JWT tokens.
It can be disabled by setting `cookie` to `false`.
* **name** - Cookie name.
* **options** - Cookie options.
* `options.expires` can be used to speficy cookie lifetime in days. Default is session only.
### `fetchUserOnLogin`
* Default: `true`
If enabled, user will be auto fetched after login.
### `resetOnError`
* Default: `false`
If enabled, user will be automatically logged out if any error happens. (For example when token expired)
### `rewriteRedirects`
* Default: `true`
If enabled, user will redirect back to the original guarded route instead of `redirects.home`.
### `watchLoggedIn`
* Default: `true`
If enabled, user will automatically redirected to `redirects.home` after login/logout.
### `namespace`
* Default: `auth`
Vuex store namespace for keeping state.
### `scopeKey`
* Default: `scope`
`user` object proprty used for scope checkings (`hasScope`). Can be either an array or a object.
## License
[MIT License](./LICENSE) - Copyright (c) Nuxt Community
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc