Skip to content
Snippets Groups Projects
Commit 3f8aaf27 authored by Layla Hough's avatar Layla Hough
Browse files

Merge branch 'fixPopUp' into 'main'

Fix pop up

See merge request !29
parents c41fb3a9 3936a014
No related branches found
No related tags found
1 merge request!29Fix pop up
...@@ -5,26 +5,40 @@ import { useNavigate } from "react-router-dom"; ...@@ -5,26 +5,40 @@ import { useNavigate } from "react-router-dom";
import axios from "axios"; import axios from "axios";
function Login() { function Login() {
const [error, setError] = useState(""); // State for error message const [error, setError] = useState("");
const navigate = useNavigate(); const navigate = useNavigate();
// Call backend CAS for login // call backend CAS for login
// const handleLogin = () => {
// const casLoginUrl = `${process.env.REACT_APP_API_URL}/login`;
// // Redirect the user to the CAS login page via backend
// window.location.href = casLoginUrl;
// };
const handleLogin = async () => { const handleLogin = async () => {
const casLoginUrl = `${process.env.REACT_APP_API_URL}/login`; const casLoginUrl = `${process.env.REACT_APP_API_URL}/login`;
try { try {
// Make a request to check if the user exists (Optional, if you want to verify before redirect) // Make an HTTP request (GET or POST) to your backend to check if it's successful
const response = await axios.post(casLoginUrl); const response = await fetch(casLoginUrl, { method: 'GET' }); // or POST depending on your backend
// If the login was successful, proceed with the CAS login redirection if (response.ok) {
window.location.href = casLoginUrl; // If the response is OK, proceed to redirect to the CAS login page
window.location.href = casLoginUrl;
} else {
// If the response is not OK (i.e., failed), you can show an error
const errorData = await response.json();
console.log("Error:", errorData.message);
setError("User Not Found!\n Please try again or login as guest."); // Optionally set an error message in the state
}
} catch (err) { } catch (err) {
// Handle errors (e.g., user not found) console.error("Network error or backend failure:", err);
setError("User Not Found!\nPlease try again or continue as guest."); setError("Network error or backend failure");
} }
}; };
// Redirect to home page without a JWT token // redirect to home page without a jwt token
const handleGuest = () => { const handleGuest = () => {
navigate("/home"); navigate("/home");
}; };
...@@ -33,6 +47,7 @@ function Login() { ...@@ -33,6 +47,7 @@ function Login() {
const closeErrorPopup = () => { const closeErrorPopup = () => {
setError(""); // Reset the error message setError(""); // Reset the error message
}; };
return ( return (
<div className="container"> <div className="container">
...@@ -40,7 +55,6 @@ function Login() { ...@@ -40,7 +55,6 @@ function Login() {
<div className="text">VT Corps Directory Log In Page</div> <div className="text">VT Corps Directory Log In Page</div>
<div className="underline"></div> <div className="underline"></div>
</div> </div>
{/* Conditionally render error message */} {/* Conditionally render error message */}
{error && ( {error && (
<div className="error-popup"> <div className="error-popup">
...@@ -58,7 +72,6 @@ function Login() { ...@@ -58,7 +72,6 @@ function Login() {
</div> </div>
</div> </div>
)} )}
<div className="inputs"> <div className="inputs">
<div className="home-auth"> <div className="home-auth">
<button className="login-button" onClick={handleLogin}> <button className="login-button" onClick={handleLogin}>
...@@ -71,6 +84,7 @@ function Login() { ...@@ -71,6 +84,7 @@ function Login() {
</button> </button>
</div> </div>
</div> </div>
{/* <div className="forgot-password">Forgot Password <span> Click here</span></div> */}
<div className="submitTerms"> <div className="submitTerms">
I agree to terms of use I agree to terms of use
<img src={user_icon} alt="" /> <img src={user_icon} alt="" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment