Skip to content

Commit 87a25dc

Browse files
Merge pull request #178 from NickBolles/njb/ini-auth-enhancements
Add feathersClient argument on initAuth to set JWT
2 parents 93e646c + dceef68 commit 87a25dc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const authDefaults = {
4040
}
4141

4242
export const initAuth = function initAuth (options) {
43-
const { commit, req, moduleName, cookieName } = Object.assign({}, authDefaults, options)
43+
const { commit, req, moduleName, cookieName, feathersClient } = Object.assign({}, authDefaults, options)
4444

4545
if (typeof commit !== 'function') {
4646
throw new Error('You must pass the `commit` function in the `initAuth` function options.')
@@ -55,6 +55,9 @@ export const initAuth = function initAuth (options) {
5555
if (payload) {
5656
commit(`${moduleName}/setAccessToken`, accessToken)
5757
commit(`${moduleName}/setPayload`, payload)
58+
if (feathersClient) {
59+
return feathersClient.passport.setJWT(accessToken).then(() => payload)
60+
}
5861
}
5962
return Promise.resolve(payload)
6063
}

test/utils.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Vue.use(Vuex)
1010
const { service, auth } = feathersNuxt(feathersClient)
1111

1212
describe('Utils', function () {
13-
it('properly populates auth', function (done) {
13+
it('properly populates auth', function () {
1414
const store = new Vuex.Store({
1515
plugins: [
1616
service('todos'),
@@ -23,7 +23,7 @@ describe('Utils', function () {
2323
cookie: 'feathers-jwt=' + accessToken
2424
}
2525
}
26-
initAuth({
26+
return initAuth({
2727
commit: store.commit,
2828
req,
2929
moduleName: 'auth',
@@ -32,7 +32,10 @@ describe('Utils', function () {
3232
.then(payload => {
3333
assert(store.state.auth.accessToken === accessToken, 'the token was in place')
3434
assert(store.state.auth.payload, 'the payload was set')
35-
done()
35+
return feathersClient.passport.getJWT()
36+
})
37+
.then((token) => {
38+
assert.isDefined(token, 'the feathers client storage was set')
3639
})
3740
})
3841
})

0 commit comments

Comments
 (0)