diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index b833981..bc95175 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -95,7 +95,12 @@ app.post('/addquestion', async (req, res) => { // Forward the add question request to the question service const addQuestionResponse = await axios.post( questionServiceUrl + '/addquestion', - req.body + req.body, + { + headers: { + Authorization: req.headers.authorization, + }, + } ); res.json(addQuestionResponse.data); } catch (error) { @@ -121,8 +126,6 @@ app.get('/questions', async (req, res) => { }); app.get('/game-questions', async (req, res) => { - console.log('gw'); - console.log(req.headers.authorization); try { // Forward the get question request to the question service const getQuestionResponse = await axios.get( @@ -142,8 +145,6 @@ app.get('/game-questions', async (req, res) => { }); app.post('/addstat', async (req, res) => { - console.log('gw'); - console.log(req.headers.authorization); try { // Forward the add stat request to the stat service const addStatResponse = await axios.post( diff --git a/statservice/stat-controller.js b/statservice/stat-controller.js index 51a25aa..1a4f888 100644 --- a/statservice/stat-controller.js +++ b/statservice/stat-controller.js @@ -20,9 +20,6 @@ export const addStatController = async (req, res) => { 'points', ]); - console.log('addstat'); - console.log(req.user.userId); - const newStat = new Stat({ userId: req.user.userId, gameId: req.body.gameId, diff --git a/users/userservice/user-controller.js b/users/userservice/user-controller.js index bb8a1bb..77ac38f 100644 --- a/users/userservice/user-controller.js +++ b/users/userservice/user-controller.js @@ -17,7 +17,8 @@ export const addUserController = async (req, res) => { // Encrypt the password before saving it const hashedPassword = await bcrypt.hash(req.body.password, 10); - + const isFirstAccount = (await User.countDocuments()) === 0; + req.body.role = isFirstAccount ? 'admin' : 'user'; const newUser = new User({ name: req.body.name, lastName: req.body.lastName, diff --git a/webapp/src/components/AddQuestionContainer.jsx b/webapp/src/components/AddQuestionContainer.jsx index 887cf8d..c622954 100644 --- a/webapp/src/components/AddQuestionContainer.jsx +++ b/webapp/src/components/AddQuestionContainer.jsx @@ -25,15 +25,24 @@ const AddQuestionContainer = () => { wrong3, }) => { try { - await axios.post(`${apiEndpoint}/addquestion`, { - type, - name, - path, - right, - wrong1, - wrong2, - wrong3, - }); + const token = localStorage.getItem('token'); + await axios.post( + `${apiEndpoint}/addquestion`, + { + type, + name, + path, + right, + wrong1, + wrong2, + wrong3, + }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); setOpenSnackbar(true); } catch (error) { console.log(error); diff --git a/webapp/src/pages/Login.jsx b/webapp/src/pages/Login.jsx index 97f2393..e2b4fd1 100644 --- a/webapp/src/pages/Login.jsx +++ b/webapp/src/pages/Login.jsx @@ -28,13 +28,14 @@ const Login = () => { withCredentials: true, } ); - console.log(response.data); const { token } = response.data; localStorage.setItem('token', token); // Guarda el token - console.log(token); setOpenSnackbar(true); - navigate('/dashboard'); + // AƱadir un retardo antes de navegar + setTimeout(() => { + navigate('/dashboard'); + }, 2000); // 2000 ms = 2 segundos } catch (error) { setError(error.response.data.error); }