multy-stub/server/routers/epja-2024-1/cats/auth/index.js

17 lines
517 B
JavaScript
Raw Permalink Normal View History

2024-10-16 11:06:23 +03:00
const authRouter = require('express').Router()
const { TOKEN } = require('../const')
2024-10-12 13:23:16 +03:00
2024-10-12 13:04:51 +03:00
2024-10-16 11:06:23 +03:00
module.exports = authRouter
2024-10-12 13:04:51 +03:00
authRouter.post('/login', (req, res) => {
2024-10-16 11:06:23 +03:00
const { email, password } = req.body
console.log(`Login with email=${email} and password=${password}`)
2024-10-12 13:04:51 +03:00
if (email === 'admin@admin.admin' && password === 'admin') {
2024-10-16 11:06:23 +03:00
res.status(200).send({ 'status': 'OK', 'data': `${TOKEN}` })
2024-10-12 13:04:51 +03:00
} else {
2024-10-16 11:06:23 +03:00
res.status(401).send({ 'status': 'Failed!', 'data': 'Invalid email or password' })
2024-10-12 13:04:51 +03:00
}
2024-10-16 11:06:23 +03:00
})