traxxx-web/src/web/auth.js

36 lines
659 B
JavaScript
Executable File

/* eslint-disable no-param-reassign */
import { login, signup } from '../auth.js';
export async function setUserApi(req, res, next) {
if (req.session.user) {
req.user = req.session.user;
}
next();
}
export async function loginApi(req, res) {
const user = await login(req.body);
req.session.user = user;
res.send(user);
}
export async function logoutApi(req, res) {
req.session.destroy((error) => {
if (error) {
res.status(500).send();
}
res.status(204).send();
});
}
export async function signupApi(req, res) {
const user = await signup(req.body);
req.session.user = user;
res.send(user);
}
/* eslint-enable no-param-reassign */