Skip to content

Commit eebf75e

Browse files
committed
Update auth docs
1 parent 6c2291f commit eebf75e

File tree

1 file changed

+25
-40
lines changed

1 file changed

+25
-40
lines changed

docs/auth-plugin.md

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,35 @@
22
title: Auth Plugin
33
---
44

5-
The Auth module helps setup your app for login / logout. It includes the following state by default:
5+
The Auth module assists setting up user login and logout.
6+
7+
## Setup
8+
9+
See the [Auth Setup](/api-overview.html#auth-plugin) section for an example of how to setup the Auth Plugin.
10+
11+
## Breaking Changes in 2.0
12+
13+
The following breaking changes were made between 1.x and 2.0:
14+
15+
- The `auth` method is now called `makeAuthPlugin`.
16+
17+
## Configuration
18+
19+
You can provide a `userService` in the auth plugin's options to automatically populate the user upon successful login.
20+
21+
## State
22+
23+
It includes the following state by default:
624

725
```js
826
{
927
accessToken: undefined, // The JWT
1028
payload: undefined, // The JWT payload
1129

30+
userService: null, // Specify the userService to automatically populate the user upon login.
1231
entityIdField: 'userId', // The property in the payload storing the user id
1332
responseEntityField: 'user', // The property in the payload storing the user
33+
user: null, // automatically populates if you have correctly configured the three previous settings.
1434

1535
isAuthenticatePending: false,
1636
isLogoutPending: false,
@@ -20,48 +40,13 @@ The Auth module helps setup your app for login / logout. It includes the follow
2040
}
2141
```
2242

23-
## Breaking Changes in 2.0
24-
25-
The following breaking changes were made between 1.x and 2.0:
26-
27-
- The `auth` method is now called `makeAuthPlugin`.
28-
29-
## Setup
30-
31-
See the [Auth Setup](/api-overview.html#auth-plugin) section for an example of how to setup the Auth Plugin.
32-
33-
## Configuration
34-
35-
36-
You can provide a `userService` in the auth plugin's options to automatically populate the user upon successful login.
37-
38-
```js
39-
import Vuex from 'vuex'
40-
import feathersClient from './feathers-client'
41-
import feathersVuex from 'feathers-vuex'
42-
43-
const { auth } = feathersVuex(feathersClient, { idField: '_id' })
44-
45-
const store = new Vuex.Store({
46-
plugins: [
47-
auth({
48-
userService: 'users', // if your user service endpoint is named 'users'
49-
entityIdField: 'userId', // The property in the payload storing the user id
50-
responseEntityField: 'user', // The property in the payload storing the user
51-
state: {}, // Custom state
52-
getters: {}, // Custom getters
53-
mutations: {}, // Custom mutations
54-
actions: {} // Custom actions
55-
})
56-
]
57-
})
58-
```
59-
6043
## Actions
6144

62-
The following actions are included in the `auth` module:
45+
The following actions are included in the `auth` module. Login is accomplished through the `authenticate` action. For logout, use the `logout` action. It's important to note that the records that were loaded for a user are NOT automatically cleared upon logout. Because the business logic requirements for that feature would vary from app to app, it can't be baked into Feathers-Vuex. It must be manually implemented. The recommended solution is to simply refresh the browser, which clears the data from memory.
6346

6447
- `authenticate`: use instead of `feathersClient.authenticate()`
6548
- `logout`: use instead of `feathersClient.logout()`
6649

67-
> Node: The Vuex auth store may not update if you use the feathers client version of the above methods.
50+
If you provided a `userService` and have correctly configured your `entityIdField` and `responseEntityField` (the defaults work with Feathers V4 out of the box), the `user` state will be updated with the logged-in user. The record will also be reactive, which means when the user record updates (in the users service) the auth user will automatically update, as well.
51+
52+
> Note: The Vuex auth store will not update if you use the feathers client version of the above methods.

0 commit comments

Comments
 (0)