stackpress
Version:
Incept is a content management framework.
26 lines (25 loc) • 934 B
JavaScript
import { signin } from '../actions.js';
export default async function AuthSignin(req, res, ctx) {
const type = req.data.path('type', 'username');
const password = req.data.path('password', true);
const engine = ctx.plugin('database');
const client = ctx.plugin('client');
const seed = ctx.config.path('database.seed', 'abc123');
const response = await signin(type, req.data(), seed, engine, client, Boolean(password));
if (response.results) {
const results = response.results;
delete results.secret;
}
res.fromStatusResponse(response);
if (response.code !== 200) {
return;
}
const session = ctx.plugin('session');
const results = response.results;
res.session.set(session.key, await session.create({
id: results.profile.id,
name: results.profile.name,
image: results.profile.image,
roles: results.profile.roles
}));
}