Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corps-directory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fhurtado14
corps-directory
Commits
3f8aaf27
Commit
3f8aaf27
authored
3 months ago
by
Layla Hough
Browse files
Options
Downloads
Plain Diff
Merge branch 'fixPopUp' into 'main'
Fix pop up See merge request
!29
parents
c41fb3a9
3936a014
No related branches found
Branches containing commit
No related tags found
1 merge request
!29
Fix pop up
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/components/Login/Login.js
+27
-13
27 additions, 13 deletions
frontend/src/components/Login/Login.js
with
27 additions
and
13 deletions
frontend/src/components/Login/Login.js
+
27
−
13
View file @
3f8aaf27
...
@@ -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
)
{
// Hand
le
error
s (e.g., user not found)
conso
le
.
error
(
"
Network error or backend failure:
"
,
err
);
setError
(
"
User Not Found!
\n
Please try again or continue as guest.
"
);
setError
(
"
Network error or backend failure
"
);
}
}
};
};
//
R
edirect to home page without a
JWT
token
//
r
edirect 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
=
""
/>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment