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 ++++++++++++++++++++++++++++++++++++ src/api/routes/auth/deviceRoutes.js | 36 ++++++++++++++++++++++++++++++++++++ src/api/routes/auth/index.js | 2 +- src/api/routes/auth/registerRoute.js | 20 -------------------- 4 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 src/api/routes/auth/accountRoutes.js create mode 100644 src/api/routes/auth/deviceRoutes.js delete mode 100644 src/api/routes/auth/registerRoute.js (limited to 'src/api/routes') 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(); + } +}; diff --git a/src/api/routes/auth/deviceRoutes.js b/src/api/routes/auth/deviceRoutes.js new file mode 100644 index 0000000..6655ecb --- /dev/null +++ b/src/api/routes/auth/deviceRoutes.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(); + } +}; diff --git a/src/api/routes/auth/index.js b/src/api/routes/auth/index.js index 7113a17..29a07ad 100644 --- a/src/api/routes/auth/index.js +++ b/src/api/routes/auth/index.js @@ -1 +1 @@ -export * from './registerRoute.js'; +export * from './accountRoutes.js'; diff --git a/src/api/routes/auth/registerRoute.js b/src/api/routes/auth/registerRoute.js deleted file mode 100644 index 87762d3..0000000 --- a/src/api/routes/auth/registerRoute.js +++ /dev/null @@ -1,20 +0,0 @@ -import { registerUser } from '#db/index.js'; -import { LoginDto, RegisterDto } from '#dto/index.js'; - -export const registerRoute = { - route: '/auth/register', - async onPost(req, res) { - const data = await RegisterDto.create(req.body); - await registerUser(data); - res.send(data); - } -}; - -export const loginRoute = { - route: '/auth/login', - async onPost(req, res) { - const data = await LoginDto.create(req.body); - await registerUser(data); - res.send(data); - } -}; -- cgit 1.5.1