Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function authUser (ctx, next) {
// user local authentication strategy
try {
return passport.authenticate('local', (err, user) => {
if (err || !user) {
ctx.throw(401)
}
const token = user.generateToken()
const response = user.toJSON()
delete response.password
ctx.status = constants.STATUS_CODE.SUCCESS_STATUS
ctx.body = {
user: response
}
ctx.append('Authorization', token);
})(ctx, next)
} catch (error) {
ctx.body = error;
ctx.status = constants.STATUS_CODE.INTERNAL_SERVER_ERROR_STATUS
}
passport.authenticate('bearer', { session: false }),
heroesController.show
);
app.put('/heroes/me/increase/:area(skills)/:id',
passport.authenticate('bearer', { session: false }),
heroesController.increase
);
app.put('/heroes/me/increase/:area(abilities|parameters)/:name',
passport.authenticate('bearer', { session: false }),
heroesController.increase
);
app.patch('/heroes/me',
passport.authenticate('bearer', { session: false }),
heroesController.update
);
app.put('/heroes/me/change-password',
passport.authenticate('bearer', { session: false }),
heroesController.changePassword
);
// TODO: Think about sep heroes controller to sep
// things, complects, island, building
app.del('/heroes/me/things/:id',
passport.authenticate('bearer', { session: false }),
heroesController.removeThing
);
app.put('/heroes/me/things/:id/dress',
router.get('/custom', async(ctx, next) => {
await passport.authenticate('jwt', function (err, user) {
if (user) {
ctx.body = "hello " + user.displayName;
} else {
ctx.body = "No such user";
console.log("err", err)
}
} )(ctx, next)
});
router.post('/login', async (ctx, next) => {
return passport.authenticate('local', (err, user) => {
if (user === false) {
ctx.body = { success: false }
ctx.throw(401)
} else {
ctx.body = { success: true }
return ctx.login(user)
}
})(ctx)
await next()
})
router.post('/login', async (ctx, next) => {
let middleware = passport.authenticate('local', async(user, info) => {
if (user === false) {
ctx.body = {
'status' : 400
}
} else {
await ctx.login(user)
ctx.body = {
user: user
}
}
})
await middleware.call(this, ctx, next)
})
export function isClientAuthenticated() {
return passport.authenticate('client-basic', { session: false });
}
export function isFacebookAuthenticatedCallback() {
return passport.authenticate('facebook', {
failureRedirect: '/login',
});
}
export function authorize() {
return passport.authenticate('jwt', { session: false });
}
export function isAuthenticated() {
return passport.authenticate('jwt');
}
export default api => {
api.get('/auth/slack',
async (ctx, next) => {
ctx.session.returnURL = ctx.query.returnURL;
delete ctx.query.returnURL;
await next();
},
passport.authenticate('slack'));
api.get('/auth/slack-admin', passport.authenticate('slack-admin', {
state: 'admin'
}));
api.get('/auth/slack/callback', async (ctx) => {
const name = ctx.query.state === 'admin' ? 'slack-admin' : 'slack';
try {
await passport.authenticate(name, {
successRedirect: '/',
failureRedirect: '/error',
}, function(user, info, status) {
if (user === false) {
ctx.redirect('/error')
} else {
ctx.login(user);
ctx.redirect(ctx.session.returnURL ? ctx.session.returnURL : '/');
if (ctx.query.state === 'admin') {