From bec70f1d4a8f82f39759086fc5a3a037586e1bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?adri=C3=A1n?= Date: Fri, 8 Mar 2024 11:09:21 +0100 Subject: [PATCH] Removed token cookie --- gatewayservice/gateway-service.js | 20 -------------------- users/authservice/auth-service.js | 6 +----- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 5d1f47d..7dd7eca 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -2,7 +2,6 @@ const express = require('express'); const axios = require('axios'); const cors = require('cors'); const promBundle = require('express-prom-bundle'); -const cookieParser = require('cookie-parser'); const app = express(); const port = 8000; @@ -11,24 +10,8 @@ const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002'; const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001'; const questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8010'; -function parseCookies(response) { - const cookies = {}; - const cookieHeader = response.headers['set-cookie'] - - if (cookieHeader) { - const cookieStrings = Array.isArray(cookieHeader) ? cookieHeader : [cookieHeader]; - for (const cookieString of cookieStrings) { - const [name, value] = cookieString.split(';')[0].split('='); - cookies[name.trim()] = value.trim(); - } - } - - return cookies; -} - app.use(cors()); app.use(express.json()); -app.use(cookieParser()); //Prometheus configuration const metricsMiddleware = promBundle({includeMethod: true}); @@ -43,9 +26,6 @@ app.post('/login', async (req, res) => { try { // Forward the login request to the authentication service const authResponse = await axios.post(authServiceUrl+'/login', req.body); - const cookies = parseCookies(authResponse) - const token = cookies.token - res.cookie('token', token) res.json(authResponse.data); } catch (error) { res.status(error.response.status).json({ error: error.response.data.error }); diff --git a/users/authservice/auth-service.js b/users/authservice/auth-service.js index 6641650..a05dd51 100644 --- a/users/authservice/auth-service.js +++ b/users/authservice/auth-service.js @@ -3,15 +3,12 @@ const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken'); const User = require('./auth-model'); -const cookieParser = require('cookie-parser') const app = express(); const port = 8002; // Middleware to parse JSON in request body app.use(express.json()); -// Middleware to do anything related with cookies -app.use(cookieParser()) // Connect to MongoDB const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb'; @@ -39,9 +36,8 @@ app.post('/login', async (req, res) => { // Check if the user exists and verify the password if (user && await bcrypt.compare(password, user.password)) { - // Generate a JWT token and save it in a cookie + // Generate a JWT token const token = jwt.sign({ userId: user._id }, 'your-secret-key', { expiresIn: '1h' }); - res.cookie('token', token); // Respond with the token and user information res.json({ token: token, username: username, createdAt: user.createdAt }); } else {