Skip to content

Commit 8e2250c

Browse files
committed
compatibility with [email protected] auth
1 parent 3599e07 commit 8e2250c

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

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

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,36 @@ export default function makeAuthActions(feathersClient) {
2929
responseHandler({ commit, state, dispatch }, response) {
3030
if (response.accessToken) {
3131
commit('setAccessToken', response.accessToken)
32+
commit('setPayload', response)
3233

33-
// Decode the token and set the payload, but return the response
34-
return feathersClient.passport
35-
.verifyJWT(response.accessToken)
36-
.then(payload => {
37-
commit('setPayload', payload)
34+
// Handle when user is returned in the authenticate response
35+
let user = response[state.responseEntityField]
3836

39-
let user = response[state.responseEntityField]
40-
41-
// If a user was returned in the authenticate response, use that user.
42-
if (user) {
43-
if (state.serverAlias && state.userService) {
44-
const Model = Object.keys(models[state.serverAlias])
45-
.map(modelName => models[state.serverAlias][modelName])
46-
.find(model => model.servicePath === state.userService)
47-
if (Model) {
48-
user = new Model(user)
49-
}
50-
}
51-
commit('setUser', user)
52-
// Populate the user if the userService was provided
53-
} else if (
54-
state.userService &&
55-
payload.hasOwnProperty(state.entityIdField)
56-
) {
57-
return dispatch(
58-
'populateUser',
59-
payload[state.entityIdField]
60-
).then(() => {
61-
commit('unsetAuthenticatePending')
62-
return response
63-
})
64-
} else {
65-
commit('unsetAuthenticatePending')
37+
if (user) {
38+
if (state.serverAlias && state.userService) {
39+
const Model = Object.keys(models[state.serverAlias])
40+
.map(modelName => models[state.serverAlias][modelName])
41+
.find(model => model.servicePath === state.userService)
42+
if (Model) {
43+
user = new Model(user)
6644
}
45+
}
46+
commit('setUser', user)
47+
commit('unsetAuthenticatePending')
48+
} else if (
49+
state.userService &&
50+
response.hasOwnProperty(state.entityIdField)
51+
) {
52+
return dispatch(
53+
'populateUser',
54+
response[state.entityIdField]
55+
).then(() => {
56+
commit('unsetAuthenticatePending')
6757
return response
6858
})
59+
}
60+
return response
61+
6962
// If there was not an accessToken in the response, allow the response to pass through to handle two-factor-auth
7063
} else {
7164
return response

0 commit comments

Comments
 (0)