Const file for token

This commit is contained in:
Mikhail 2024-10-12 13:23:16 +03:00
parent 0c693e1bac
commit 528b37246b
4 changed files with 8 additions and 4 deletions

View File

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

View File

@ -1,5 +1,6 @@
const authRouter = require('express').Router();
require('dotenv').config();
const { TOKEN } = require('../const');
module.exports = authRouter;
@ -8,7 +9,7 @@ authRouter.post('/login', (req, res) => {
console.log(`Login with email=${email} and password=${password}`);
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 {
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();
require('dotenv').config();
const data = require('../data.json');
rootRouter.get('/get/nickname', (req, res) => {