Skip to content

Commit 05e348e

Browse files
committed
Prepare for two-factor auth scenarios
1 parent 90c87b2 commit 05e348e

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/auth-module/actions.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@ export default function makeAuthActions (feathersClient) {
99
}
1010
return feathersClient.authenticate(data)
1111
.then(response => {
12-
commit('setAccessToken', response.accessToken)
12+
if (response.accessToken) {
13+
commit('setAccessToken', response.accessToken)
1314

14-
// Decode the token and set the payload, but return the response
15-
return feathersClient.passport.verifyJWT(response.accessToken)
16-
.then(payload => {
17-
commit('setPayload', payload)
15+
// Decode the token and set the payload, but return the response
16+
return feathersClient.passport.verifyJWT(response.accessToken)
17+
.then(payload => {
18+
commit('setPayload', payload)
1819

19-
// Populate the user if the userService was provided
20-
if (state.userService && payload.hasOwnProperty('userId')) {
21-
return dispatch('populateUser', payload.userId)
22-
.then(() => {
23-
commit('unsetAuthenticatePending')
24-
return response
25-
})
26-
} else {
27-
commit('unsetAuthenticatePending')
28-
}
29-
return response
30-
})
20+
// Populate the user if the userService was provided
21+
if (state.userService && payload.hasOwnProperty('userId')) {
22+
return dispatch('populateUser', payload.userId)
23+
.then(() => {
24+
commit('unsetAuthenticatePending')
25+
return response
26+
})
27+
} else {
28+
commit('unsetAuthenticatePending')
29+
}
30+
return response
31+
})
32+
// If there was not an accessToken in the response, allow the response to pass through to handle two-factor-auth
33+
} else {
34+
return response
35+
}
3136
})
3237
.catch(error => {
3338
commit('setAuthenticateError', error)

0 commit comments

Comments
 (0)