passport-local
passport-local copied to clipboard
usernameField and passwordField compatible with jsonapi standard.
Hi
According to jsonapi (http://jsonapi.org/). I send this json to login in my api server:
{
"data": {
"type": "user",
"Attributes": {
"email": "[email protected]",
"password": "thepasskey"
}
}
}
How can i put this in userField and passwordField? (the example don't work)
passport.use(new LocalStrategy(
{
usernameField: 'data.Attributes.email',
passwordField: 'data.Attributes.password'
},
function(email, password, done) {
Thanks :)
(Jsonapi is an STANDARD)
Replace '.'
with '[]'
to access nested object, I think there is a bug in lookup function
passport.use(new LocalStrategy(
{
usernameField: 'data[]Attributes[]email',
passwordField: 'data[]Attributes[]password'
},
function(email, password, done) {
@zipper97412 many thanks! Looking at the lookup functions this is how it works: https://github.com/jaredhanson/passport-local/blob/3b9980f6467fd1203ecf8844fb017b5db2941606/lib/utils.js#L3
Have you considered using the passport-custom strategy instead? It is even more stripped back than passport-local, and makes no assumptions about how you are passing in the email and password.
So for example you can read them from a JSON post as in your JSON:API example.
I think the supposed way to provide a nested field is usernameField: 'data[Attributes][email]'
which results in a "chain" of ['data', 'Attributes', 'email']