From 0ca7c01bc4a6c5ab50ac80f9a8e5d5c5db442f45 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 1 Jun 2025 08:04:30 +0200 Subject: Register works, part of login and auth middleware --- src/api/routes/auth/accountRoutes.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/api/routes/auth/accountRoutes.js (limited to 'src/api/routes/auth/accountRoutes.js') diff --git a/src/api/routes/auth/accountRoutes.js b/src/api/routes/auth/accountRoutes.js new file mode 100644 index 0000000..6655ecb --- /dev/null +++ b/src/api/routes/auth/accountRoutes.js @@ -0,0 +1,36 @@ +import { deleteUser, loginUser, registerUser } from '#db/index.js'; +import { AuthDto, RegisterDto } from '#dto/index.js'; + +export const registerRoute = { + route: '/auth/register', + async onPost(req, res) { + const data = await RegisterDto.create(req.body); + const registerResult = await registerUser(data); + res.send(registerResult); + } +}; + +export const loginRoute = { + route: '/auth/login', + /** + * + * @param req {Request} + * @param res + * @returns {Promise} + */ + async onPost(req, res) { + const data = await AuthDto.create(req.body); + console.log(req.headers['user-agent']); + const loginResult = await loginUser(data, req.headers['user-agent']); + res.send(loginResult); + } +}; + +export const deleteRoute = { + route: '/auth/delete', + async onDelete(req, res) { + const data = await AuthDto.create(req.body); + await deleteUser(data); + res.status(204).send(); + } +}; -- cgit 1.5.1