Feat: Added the logic to save the username and token into the localhost alongside the expiryId. Add Login page component in Authentication module
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { FiEye, FiEyeOff } from "react-icons/fi";
|
import { FiEye, FiEyeOff } from "react-icons/fi";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import toast from "react-hot-toast"; // Import React Hot Toast
|
import toast from "react-hot-toast"; // Import React Hot Toast
|
||||||
|
|
||||||
|
|
||||||
const API_URL = import.meta.env.VITE_API_URL; // Using .env variable
|
const API_URL = import.meta.env.VITE_API_URL; // Using .env variable
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
@@ -52,6 +51,14 @@ const Login = () => {
|
|||||||
// On success, store the token in localStorage
|
// On success, store the token in localStorage
|
||||||
localStorage.setItem("token", data.token);
|
localStorage.setItem("token", data.token);
|
||||||
localStorage.setItem("expiresIn", data.expiresIn);
|
localStorage.setItem("expiresIn", data.expiresIn);
|
||||||
|
fetch(`${API_URL}/api/hdfs/getUsernameByEmail?email=${email}`)
|
||||||
|
.then((response) => response.text())
|
||||||
|
.then((username) => {
|
||||||
|
localStorage.setItem("username", username);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error fetching username:", error);
|
||||||
|
});
|
||||||
|
|
||||||
// Show success toast
|
// Show success toast
|
||||||
toast.success("Login successful!");
|
toast.success("Login successful!");
|
||||||
@@ -65,7 +72,7 @@ const Login = () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Dismiss the loading toast and show error
|
// Dismiss the loading toast and show error
|
||||||
toast.dismiss(toastId);
|
toast.dismiss(toastId);
|
||||||
toast.error("An error occurred. Please try again.");
|
toast.error("An error occurred. Please try again.", error);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -144,4 +151,4 @@ const Login = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Login;
|
export default Login;
|
||||||
|
|||||||
Reference in New Issue
Block a user