diff --git a/server/routers/epja-2024-1/cats/admin/index.js b/server/routers/epja-2024-1/cats/admin/index.js index 351bd19..66d8af9 100644 --- a/server/routers/epja-2024-1/cats/admin/index.js +++ b/server/routers/epja-2024-1/cats/admin/index.js @@ -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' }); diff --git a/server/routers/epja-2024-1/cats/auth/index.js b/server/routers/epja-2024-1/cats/auth/index.js index 933c810..51a26a7 100644 --- a/server/routers/epja-2024-1/cats/auth/index.js +++ b/server/routers/epja-2024-1/cats/auth/index.js @@ -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' }); } diff --git a/server/routers/epja-2024-1/cats/const.js b/server/routers/epja-2024-1/cats/const.js new file mode 100644 index 0000000..7e32060 --- /dev/null +++ b/server/routers/epja-2024-1/cats/const.js @@ -0,0 +1,3 @@ +const TOKEN = "ASDFGHJKLLKJHGFDSDFGHJKJHGF"; + +module.exports = { TOKEN } \ No newline at end of file diff --git a/server/routers/epja-2024-1/cats/root/index.js b/server/routers/epja-2024-1/cats/root/index.js index 0bfc9a7..ad2b541 100644 --- a/server/routers/epja-2024-1/cats/root/index.js +++ b/server/routers/epja-2024-1/cats/root/index.js @@ -1,5 +1,4 @@ const rootRouter = require('express').Router(); -require('dotenv').config(); const data = require('../data.json'); rootRouter.get('/get/nickname', (req, res) => {