create-myexam-app 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
|
-
import
|
|
2
|
+
import {useNavigate} from 'react-router-dom'
|
|
3
|
+
import axios from 'axios'
|
|
3
4
|
|
|
4
5
|
export default function Login() {
|
|
5
6
|
const [email, setEmail] = useState('');
|
|
6
7
|
const [password, setPassword] = useState('');
|
|
7
8
|
const [error, setError] = useState('');
|
|
8
|
-
|
|
9
|
+
const navigate = useNavigate();
|
|
10
|
+
|
|
9
11
|
const handleLogin = async (e) => {
|
|
10
12
|
e.preventDefault();
|
|
11
13
|
try {
|
|
12
14
|
const res = await axios.post('http://localhost:5000/api/user/login', { email, password });
|
|
13
15
|
localStorage.setItem("token", res.data.token);
|
|
14
|
-
|
|
16
|
+
navigate("/dshboard");
|
|
17
|
+
window.location.reload();
|
|
15
18
|
} catch (error) {
|
|
16
|
-
|
|
19
|
+
if(error.response && error.response.data){
|
|
20
|
+
setError(error.response.data.message);
|
|
21
|
+
}else{
|
|
22
|
+
setError("Failed to login. Please check your details.")
|
|
23
|
+
}
|
|
17
24
|
}
|
|
18
25
|
};
|
|
19
26
|
|