-
-
Save Mattchewone/a4f898f0e0f6dbe27bbe54a0f186c6f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication'); | |
const { FeathersError } = require('@feathersjs/errors'); | |
const { LocalStrategy } = require('@feathersjs/authentication-local'); | |
const { expressOauth } = require('@feathersjs/authentication-oauth'); | |
class ImATeaPot extends FeathersError { | |
constructor(message, data) { | |
super(message, 'i-m-a-tea-pot', 418, 'ImATeaPot', data); | |
} | |
} | |
class MyLocalStrategy extends LocalStrategy { | |
async findEntity(username, params) { | |
const entity = await super.findEntity(username, params); | |
if (entity.isCoffeeFan) { | |
throw new ImATeaPot('User can only support tea.'); | |
} | |
return entity; | |
} | |
} | |
module.exports = app => { | |
const authentication = new AuthenticationService(app); | |
authentication.register('jwt', new JWTStrategy()); | |
authentication.register('local', new MyLocalStrategy()); | |
app.use('/authentication', authentication); | |
app.configure(expressOauth()); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication'); | |
const { FeathersError } = require('@feathersjs/errors'); | |
const { LocalStrategy } = require('@feathersjs/authentication-local'); | |
const { expressOauth } = require('@feathersjs/authentication-oauth'); | |
class ImATeaPot extends FeathersError { | |
constructor(message, data) { | |
super(message, 'i-m-a-tea-pot', 418, 'ImATeaPot', data); | |
} | |
} | |
class MyLocalStrategy extends LocalStrategy { | |
async getEntityQuery(query, params) { | |
// Query for user but only include users marked as `active` | |
return { | |
...query, | |
active: true, | |
$limit: 1 | |
} | |
} | |
async findEntity(username, params) { | |
const entity = await super.findEntity(username, params); | |
if (entity.isCoffeeFan) { | |
throw new ImATeaPot('User can only support tea.'); | |
} | |
return entity; | |
} | |
} | |
module.exports = app => { | |
const authentication = new AuthenticationService(app); | |
authentication.register('jwt', new JWTStrategy()); | |
authentication.register('local', new MyLocalStrategy()); | |
app.use('/authentication', authentication); | |
app.configure(expressOauth()); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication'); | |
const { BadRequest } = require('@feathersjs/errors'); | |
const { LocalStrategy } = require('@feathersjs/authentication-local'); | |
const { expressOauth } = require('@feathersjs/authentication-oauth'); | |
class MyLocalStrategy extends LocalStrategy { | |
async getEntityQuery(query, params) { | |
// Query for user but only include users marked as `active` | |
return { | |
...query, | |
active: true, | |
$limit: 1 | |
} | |
} | |
} | |
module.exports = app => { | |
const authentication = new AuthenticationService(app); | |
authentication.register('jwt', new JWTStrategy()); | |
authentication.register('local', new MyLocalStrategy()); | |
app.use('/authentication', authentication); | |
app.configure(expressOauth()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment