You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-48Lines changed: 42 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,82 +26,76 @@
26
26
],
27
27
// Default Values
28
28
auth: {
29
-
login: {
30
-
endpoint:'auth/login',
31
-
propertyName:'token'
32
-
},
33
-
logout: {
34
-
endpoint:'auth/logout',
35
-
method:'GET',
36
-
paramTokenName:'',
37
-
appendToken:false
38
-
},
39
-
user: {
40
-
endpoint:'auth/user',
41
-
propertyName:'user',
42
-
paramTokenName:'',
43
-
appendToken:false
44
-
},
45
-
storageTokenName:'nuxt-auth-token',
46
-
tokenType:'Bearer',
47
-
notLoggedInRedirectTo:'/login',
48
-
loggedInRedirectTo:'/'
49
-
}
29
+
user: {
30
+
endpoint:'auth/user',
31
+
propertyName:'user',
32
+
},
33
+
login: {
34
+
endpoint:'auth/login',
35
+
},
36
+
logout: {
37
+
endpoint:'auth/logout',
38
+
method:'GET',
39
+
},
40
+
redirect: {
41
+
notLoggedIn:'/login',
42
+
loggedIn:'/'
43
+
},
44
+
token: {
45
+
enabled:true,
46
+
name:'token',
47
+
cookieName:'token',
48
+
type:'Bearer'
49
+
}
50
50
}
51
51
```
52
52
53
53
## Options
54
54
55
+
#### user
56
+
Sets the global settings for store **fetch** action.
57
+
* **endpoint** - Set the URL of the user data endpoint. It can be a relative or absolute path.
58
+
* **propertyName** - Set the name of the return object property that contains the user data. If you want the entire object returned, set an empty string.
59
+
55
60
#### login
56
-
Set the global settings for the login action.
61
+
Set the global settings for store **login** action.
57
62
* **endpoint** - Set the URL of the login endpoint. It can be a relative or absolute path.
58
-
***propertyName** - Set the name of the return object property that contains the access token.
59
63
60
64
#### logout
61
-
Sets the global settings for the logout action.
65
+
Sets the global settings for store **logout** action.
62
66
* **endpoint** - Set the URL of the logout endpoint. It can be a relative or absolute path.
63
67
* **method** - Set the request to POST or GET.
64
-
***paramTokenName** - Set the access token query string parameter name.
65
-
***appendToken** - Set true if you want the access token to be inserted in the URL.
66
-
67
-
#### user
68
-
Sets the global settings for the fetch action.
69
-
***endpoint** - Set the URL of the user data endpoint. It can be a relative or absolute path.
70
-
***propertyName** - Set the name of the return object property that contains the user data. If you want the entire object returned, set an empty string.
71
-
***paramTokenName** - Set the access token query string parameter name.
72
-
***appendToken** - Set true if you want the access token to be inserted in the URL.
73
-
74
-
#### storageTokenName
75
-
Set the token name in the local storage and in the cookie.
76
-
77
-
#### tokenType
78
-
Sets the token type of the authorization header.
79
68
80
-
#### notLoggedInRedirectTo
81
-
Sets the redirect URL default of the users not logged in. This is actived when 'auth' middeware is register.
69
+
#### Token
70
+
* **enabled** - Get and use tokens for authentication.
71
+
* **name** - Set the token name in the local storage.
72
+
* **cookieName** - Set the token name in Cookies. (Set to `null` to disable)
73
+
* **type** - Sets the token type of the authorization header.
82
74
83
-
#### loggedInRedirectTo
84
-
Sets the redirect URL default of the users logged in. This is actived when 'no-auth' middeware is register.
75
+
#### redirect
76
+
* **notLoggedInRedirectTo** - Sets the redirect URL default of the users not logged in. Only when `auth` middleware is added to a page.
77
+
* **loggedInRedirectTo** - Sets the redirect URL default of the users logged in. Only when `no-auth` middleware is added to a page.
85
78
86
79
## Example usage
87
80
88
81
```js
89
82
// ... code ...
83
+
// Do a password based login
90
84
store.dispatch('auth/login', {
91
85
fields: {
92
86
username:'your_username',
93
87
password:'your_password'
94
88
}
95
-
})// run login
89
+
})
96
90
97
91
// ... code ...
98
92
store.dispatch('auth/logout') // run logout
99
93
100
94
// ... code ...
101
-
store.state['auth']['token']// get access token
95
+
store.state.auth.token// get access token
102
96
103
97
// ... code ...
104
-
store.state['auth']['user']// get user data
98
+
store.state.auth.user// get user data
105
99
106
100
// ... code ...
107
101
store.getters['auth/loggedIn'] // get login status (true or false)
@@ -113,8 +107,8 @@ store.getters['auth/loggedIn'] // get login status (true or false)
113
107
// ... in nuxt.config.js ...
114
108
router: {
115
109
middleware: [
116
-
'auth', // If user not logged in, redirect to '/login' or to URL defined in notLoggedInRedirectTo property
117
-
'no-auth'// If user is already logged in, redirect to '/' or to URL defined in loggedInRedirectTo property
110
+
'auth', // If user not logged in, redirect to '/login' or to URL defined in redirect property
111
+
'no-auth'// If user is already logged in, redirect to '/' or to URL defined in redirect property
0 commit comments