Skip to content

Commit

Permalink
Applied the session parameters into the navbar to test it.
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Andina  <[email protected]>
  • Loading branch information
alagoconde and and1na committed Mar 4, 2024
1 parent 4e3ca7a commit 7e43391
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion webapp/src/components/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ function NavBar() {

<Button component={Link} to={'/login'} sx={{ p: 0, display: 'flex', alignItems: 'center', flexGrow: 0 }} >
<Typography variant="body2" sx={{ color: 'white', textDecoration: 'none' }}>
{isLoggedIn ? ({username}):("Log In")}
{/* {isLoggedIn ? {username} : "Log In"} */}
{isLoggedIn ? "CAMBIAR" : "Log In"}
</Typography>
<IconButton >
<Avatar src="/default_user.jpg" alt="Profile pic" sx={{ width: 33, height: 33 }} />
Expand Down
14 changes: 7 additions & 7 deletions webapp/src/pages/Login.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// src/components/Login.js
import React, { useState } from 'react';
import React, { useState,useContext } from 'react';
import axios from 'axios';
import { Container, Typography, TextField, Button, Snackbar, Box, Divider } from '@mui/material';
import { Link } from 'react-router-dom';
import verifyToken from '../../../users/services/authVerifyMiddleWare';
import { SessionContext } from '../SessionContext';

const Login = () => {
const [username, setUsername] = useState('');
Expand All @@ -13,22 +13,22 @@ const Login = () => {
const [createdAt, setCreatedAt] = useState('');
const [openSnackbar, setOpenSnackbar] = useState(false);

const { createSession } = useContext(SessionContext);

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

const loginUser = async () => {
try {

const response = await axios.post(`${apiEndpoint}/login`, { username, password });

//Token received from post request.
const { token } = response.data;
localStorage.setItem('jwt', token)

// Extract data from the response
const { createdAt: userCreatedAt } = response.data;

setCreatedAt(userCreatedAt);
setLoginSuccess(true);
setOpenSnackbar(true);
createSession(username);

} catch (error) {
setError(error.response.data.error);
}
Expand Down

0 comments on commit 7e43391

Please sign in to comment.