Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
],
remove: [
auth.hooks.authenticate('jwt')
]
}
});
// Add a hook to the user service that automatically replaces
// the password with a hash of the password before saving it.
app.service('users').hooks({
before: {
find: [
auth.hooks.authenticate('jwt')
],
create: [
local.hooks.hashPassword({ passwordField: 'password' })
]
}
});
// Create a user that we can use to log in
app.service('users').create(User).catch(console.error);
// Custom Express routes
app.get('/protected', auth.express.authenticate('jwt'), (req, res, next) => {
res.json({ success: true });
});
app.get('/unprotected', (req, res, next) => {
res.json({ success: true });
});
// Hooks for service `users1`. (Can be re-generated.)
const commonHooks = require('feathers-hooks-common');
const { authenticate } = require('@feathersjs/authentication').hooks;
// eslint-disable-next-line no-unused-vars
const { hashPassword, protect } = require('@feathersjs/authentication-local').hooks;
// !code: imports // !end
// ! code: used
// eslint-disable-next-line no-unused-vars
const { iff } = commonHooks;
// eslint-disable-next-line no-unused-vars
const { create, update, patch, validateCreate, validateUpdate, validatePatch } = require('./users1.validate');
// !end
// !code: init // !end
let moduleExports = {
before: {
// Your hooks should include:
// find : authenticate('jwt')
// get : authenticate('jwt')
// ! code: before
all: [],
find: [ authenticate('jwt'), mongoKeys(ObjectID, foreignKeys) ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
// !end
},
after: {
// Your hooks should include:
// all : protect('password') /* Must always be the last hook */
// ! code: after
all: [ protect('password') /* Must always be the last hook */ ],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
// !end
},
error: {
// ! code: error
all: [],
find: [],
get: [],
create: [],
update: [],
// ! code: before
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
// !end
},
after: {
// Your hooks should include:
// all : protect('password') /* Must always be the last hook */
// ! code: after
all: [ protect('password') /* Must always be the last hook */ ],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
// !end
},
error: {
// ! code: error
all: [],
find: [],
get: [],
create: [],
update: [],
// ! code: before
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
// !end
},
after: {
// Your hooks should include:
// all : protect('password') /* Must always be the last hook */
// ! code: after
all: [ protect('password') /* Must always be the last hook */ ],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
// !end
},
error: {
// ! code: error
all: [],
find: [],
get: [],
create: [],
update: [],
// ! code: before
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
// !end
},
after: {
// Your hooks should include:
// all : protect('password') /* Must always be the last hook */
// ! code: after
all: [ protect('password') /* Must always be the last hook */ ],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
// !end
},
error: {
// ! code: error
all: [],
find: [],
get: [],
create: [],
update: [],
let moduleExports = function (app: App) {
const config = app.get('authentication');
// !code: func_init // !end
// Set up authentication with the secret
app.configure(authentication(config));
app.configure(jwt());
app.configure(local());
// !code: loc_1 // !end
app.configure(oauth2(Object.assign({
name: 'auth0',
Strategy: Auth0Strategy,
// !code: auth0_options // !end
}, config.auth0)));
app.configure(oauth2(Object.assign({
name: 'google',
Strategy: GoogleStrategy,
// !code: google_options // !end
}, config.google)));
app.configure(oauth2(Object.assign({
name: 'facebook',
enabled: true,
name: COOKIE_NAME,
httpOnly: false,
secure: false
},
jwt: {
header: { typ: 'access' },
audience: ORIGIN,
subject: 'authentication',
issuer: 'frontless',
algorithm: 'HS256',
expiresIn: '10d' // the access token expiry
},
}))
app.configure(local({
session: true,
usernameField: 'username',
passwordField: 'password',
entityUsernameField: 'username',
entityPasswordField: 'password',
Verifier,
}))
const dir = __dirname + '/..'
app.emit('setup:ssr', app)
app.use('/*@:args', Frontless(dir, ['styles']))
app.use('/*', Frontless(dir, ['styles']))
app.use((err, req, res, next) => {
const {type, code} = err;
if (type === 'FeathersError') {
},
async update() {
return []
},
async remove() {
return []
},
})
app.service('users').hooks({
before: {
create: [
local.hooks.hashPassword(),
]
},
after: local.hooks.protect('password')
})
app.service('authentication').hooks({
before: {
create: [
// You can chain multiple strategies
auth.hooks.authenticate(['local']),
],
remove: [
auth.hooks.authenticate('jwt')
]
}
});
import * as feathersAuthentication from '@feathersjs/authentication';
import * as local from '@feathersjs/authentication-local';
// Don't remove this comment. It's needed to format import lines nicely.
const { authenticate } = feathersAuthentication.hooks;
const { hashPassword, protect } = local.hooks;
export default {
before: {
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword('password') ],
update: [ hashPassword('password'), authenticate('jwt') ],
patch: [ hashPassword('password'), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
after: {
all: [
// Make sure the password field is never sent to the client
// Always must be the last hook