Skip to content

Commit b1f25a5

Browse files
committed
Auth: prefer the user from the authenticate response.
This makes it so that if a user is returned in the response to `authenticate`, that user will be commited to the store and the additional request will not be sent. This is especially useful when important server-side populating occurs during login.
1 parent aad86b4 commit b1f25a5

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/auth-module/auth-module.actions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ export default function makeAuthActions(feathersClient) {
3434
.then(payload => {
3535
commit('setPayload', payload)
3636

37-
// Populate the user if the userService was provided
38-
if (
37+
// If a user was returned in the authenticate response, use that user.
38+
if (response[state.responseEntityField]) {
39+
commit('setUser', response[state.responseEntityField])
40+
// Populate the user if the userService was provided
41+
} else if (
3942
state.userService &&
4043
payload.hasOwnProperty(state.entityIdField)
4144
) {

src/auth-module/auth-module.state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default function setupAuthState({ userService }) {
88
accessToken: null, // The JWT
99
payload: null, // The JWT payload
1010
entityIdField: 'userId',
11+
responseEntityField: 'user',
1112

1213
isAuthenticatePending: false,
1314
isLogoutPending: false,

src/make-find-mixin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function makeFindMixin(options) {
9898
// If both queries are provided, we're not using fall-through pagination.
9999
// User can pass `paginate: false` to force old behavior with a single query.
100100
if (this[FETCH_PARAMS] && this[PARAMS] || this[PARAMS] && this[PARAMS].paginate === false) {
101-
return this.$store.getters[`${this[SERVICE_NAME]}/find`](this[PARAMS]).data
101+
return this.$store.getters[`${serviceName}/find`](this[PARAMS]).data
102102
}
103103

104104
const params = this[PARAMS]

0 commit comments

Comments
 (0)