Const file for token
This commit is contained in:
parent
0c693e1bac
commit
528b37246b
@ -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' });
|
||||
|
@ -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' });
|
||||
}
|
||||
|
3
server/routers/epja-2024-1/cats/const.js
Normal file
3
server/routers/epja-2024-1/cats/const.js
Normal file
@ -0,0 +1,3 @@
|
||||
const TOKEN = "ASDFGHJKLLKJHGFDSDFGHJKJHGF";
|
||||
|
||||
module.exports = { TOKEN }
|
@ -1,5 +1,4 @@
|
||||
const rootRouter = require('express').Router();
|
||||
require('dotenv').config();
|
||||
const data = require('../data.json');
|
||||
|
||||
rootRouter.get('/get/nickname', (req, res) => {
|
||||
|
Loading…
Reference in New Issue
Block a user