Skip to content

Instantly share code, notes, and snippets.

@Mattchewone
Last active February 19, 2020 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mattchewone/a4f898f0e0f6dbe27bbe54a0f186c6f9 to your computer and use it in GitHub Desktop.
Save Mattchewone/a4f898f0e0f6dbe27bbe54a0f186c6f9 to your computer and use it in GitHub Desktop.
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());
};
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());
};
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