Cats backend routes #30

Merged
nekitboy1998 merged 2 commits from cats into master 2024-10-12 13:23:39 +03:00
4 changed files with 8 additions and 4 deletions
Showing only changes of commit 528b37246b - Show all commits

View File

@ -1,6 +1,7 @@
const adminRouter = require('express').Router(); const adminRouter = require('express').Router();
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const { TOKEN } = require('../const');
require('dotenv').config(); require('dotenv').config();
const dataFilePath = path.join(__dirname, '../data.json'); const dataFilePath = path.join(__dirname, '../data.json');
@ -8,7 +9,7 @@ let data = require('../data.json');
const verifyToken = (req, res, next) => { const verifyToken = (req, res, next) => {
const token = req.headers['authorization']; const token = req.headers['authorization'];
if (token === process.env.TOKEN) { if (token === TOKEN) {
next(); next();
} else { } else {
res.status(403).send({ 'status': 'Failed', 'data': 'Invalid token' }); res.status(403).send({ 'status': 'Failed', 'data': 'Invalid token' });

View File

@ -1,5 +1,6 @@
const authRouter = require('express').Router(); const authRouter = require('express').Router();
require('dotenv').config(); const { TOKEN } = require('../const');
module.exports = authRouter; module.exports = authRouter;
@ -8,7 +9,7 @@ authRouter.post('/login', (req, res) => {
console.log(`Login with email=${email} and password=${password}`); console.log(`Login with email=${email} and password=${password}`);
if (email === 'admin@admin.admin' && password === 'admin') { if (email === 'admin@admin.admin' && password === 'admin') {
res.status(200).send({ 'status': 'OK', 'data': `${process.env.TOKEN}` }); res.status(200).send({ 'status': 'OK', 'data': `${TOKEN}` });
} else { } else {
res.status(401).send({ 'status': 'Failed!', 'data': 'Invalid email or password' }); res.status(401).send({ 'status': 'Failed!', 'data': 'Invalid email or password' });
} }

View File

@ -0,0 +1,3 @@
const TOKEN = "ASDFGHJKLLKJHGFDSDFGHJKJHGF";
module.exports = { TOKEN }

View File

@ -1,5 +1,4 @@
const rootRouter = require('express').Router(); const rootRouter = require('express').Router();
require('dotenv').config();
const data = require('../data.json'); const data = require('../data.json');
rootRouter.get('/get/nickname', (req, res) => { rootRouter.get('/get/nickname', (req, res) => {