after login, redirect to /boxes
This commit is contained in:
parent
a9e976ecd3
commit
a618a3d602
|
@ -20,7 +20,7 @@ export default function Boxes({ token }) {
|
||||||
}, [token]);
|
}, [token]);
|
||||||
|
|
||||||
// Log boxes state changes outside the useEffect
|
// Log boxes state changes outside the useEffect
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('Boxes updated:', boxes);
|
console.log('Boxes updated:', boxes);
|
||||||
}, [boxes]);
|
}, [boxes]);
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Button, TextField, Container, Typography } from '@mui/material';
|
import { Button, TextField, Container, Typography } from '@mui/material';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { useNavigate } from 'react-router-dom'; // Import useNavigate
|
||||||
|
|
||||||
export default function Login({ setToken }) {
|
export default function Login({ setToken }) {
|
||||||
const [username, setUsername] = useState('');
|
const [username, setUsername] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
|
const navigate = useNavigate(); // Initialize useNavigate
|
||||||
const handleLogin = async (e) => {
|
const handleLogin = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
|
@ -14,6 +15,7 @@ export default function Login({ setToken }) {
|
||||||
|
|
||||||
const response = await axios.post(`${process.env.REACT_APP_API_URL}/login`, { username, password });
|
const response = await axios.post(`${process.env.REACT_APP_API_URL}/login`, { username, password });
|
||||||
setToken(response.data.token); // Store the token in state or context
|
setToken(response.data.token); // Store the token in state or context
|
||||||
|
navigate('/boxes'); //redirect to /boxes after successful login
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Login failed', error);
|
console.error('Login failed', error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue