Skip to content

Commit 3ce8647

Browse files
Merge pull request #474 from hamiltoes/feature/auth-params
feature: allow passing auth params
2 parents 275325e + 6799bf2 commit 3ce8647

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import { getNameFromPath } from '../utils'
99

1010
export default function makeAuthActions(feathersClient) {
1111
return {
12-
authenticate(store, data) {
12+
authenticate(store, dataOrArray) {
1313
const { commit, state, dispatch } = store
14+
const [data, params] = Array.isArray(dataOrArray)
15+
? dataOrArray
16+
: [dataOrArray]
1417

1518
commit('setAuthenticatePending')
1619
if (state.errorOnAuthenticate) {
1720
commit('clearAuthenticateError')
1821
}
1922
return feathersClient
20-
.authenticate(data)
23+
.authenticate(data, params)
2124
.then(response => {
2225
return dispatch('responseHandler', response)
2326
})

test/auth-module/auth-module.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { assert } from 'chai'
44
import feathersVuex from '../../src/index'
55
import { feathersRestClient as feathersClient } from '../fixtures/feathers-client'
66
import Vuex from 'vuex'
7+
import { isEmpty } from 'lodash'
78

89
const { makeAuthPlugin, makeServicePlugin, BaseModel } = feathersVuex(
910
feathersClient,
@@ -209,4 +210,43 @@ describe('Auth Module', () => {
209210
assert(store.state.auth.isTrue === true, 'the custom action was run')
210211
})
211212
})
213+
214+
it('Calls auth service without params', async function() {
215+
let receivedData = null
216+
let receivedParams = null
217+
feathersClient.use('authentication', {
218+
create(data, params) {
219+
receivedData = data
220+
receivedParams = params
221+
return Promise.resolve({ accessToken: 'jg54jh2gj6fgh734j5h4j25jbh' })
222+
}
223+
})
224+
225+
const { store } = makeContext()
226+
227+
const request = { strategy: 'local', email: 'test', password: 'test' }
228+
await store.dispatch('auth/authenticate', request)
229+
assert(receivedData, 'got data')
230+
assert(receivedData.strategy === 'local', 'got strategy')
231+
assert(receivedData.email === 'test', 'got email')
232+
assert(receivedData.password === 'test', 'got password')
233+
assert(receivedParams && isEmpty(receivedParams), 'empty params')
234+
})
235+
236+
it('Calls auth service with params', async function() {
237+
let receivedParams = null
238+
feathersClient.use('authentication', {
239+
create(data, params) {
240+
receivedParams = params
241+
return Promise.resolve({ accessToken: 'jg54jh2gj6fgh734j5h4j25jbh' })
242+
}
243+
})
244+
245+
const { store } = makeContext()
246+
247+
const request = { strategy: 'local', email: 'test', password: 'test' }
248+
const customParams = { theAnswer: 42 }
249+
await store.dispatch('auth/authenticate', [request, customParams])
250+
assert(receivedParams && receivedParams.theAnswer === 42, 'got params')
251+
})
212252
})

0 commit comments

Comments
 (0)