Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/kathy/login recaptcha #70

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions frontend/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// src/env.d.ts
declare namespace NodeJS {
type ProcessEnv = {
REACT_APP_SITE_KEY: string;
// Add other environment variables as needed
};
}
35 changes: 32 additions & 3 deletions frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FormEvent, useContext, useEffect, useState } from "react";
import { FormEvent, useContext, useEffect, useRef, useState } from "react";
import ReCAPTCHA from "react-google-recaptcha";
import { useNavigate } from "react-router-dom";

import { AuthContext } from "../contexts/AuthContext";
Expand All @@ -9,7 +10,9 @@
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [showError, setShowError] = useState(false);
const [showCaptchaError, setShowCaptchaError] = useState(false);
const [isLoginLoading, setIsLoginLoading] = useState(false);
const recaptcha = useRef<ReCAPTCHA>(null);
const navigate = useNavigate();

// Redirect once logged in
Expand All @@ -25,6 +28,19 @@
if (isLoginLoading) return;

setIsLoginLoading(true);

if (recaptcha.current) {
const captchaValue = recaptcha.current.getValue();

Check failure on line 33 in frontend/src/pages/Login.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe assignment of an `any` value

Check failure on line 33 in frontend/src/pages/Login.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe call of an `any` typed value

Check failure on line 33 in frontend/src/pages/Login.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .getValue on an `any` value
if (!captchaValue) {
setShowCaptchaError(true);
setIsLoginLoading(false);
return;
}
} else {
setShowCaptchaError(true);
setIsLoginLoading(false);
return;
}
const loginPromise = login(username, password);

if (loginPromise instanceof Promise) {
Expand All @@ -51,7 +67,7 @@
<div className={styles.sectionContent}>
<h2 className={styles.loginSectionHeader}>Login</h2>
<form onSubmit={handleSubmit} className={styles.loginForm}>
<div>
<div className={styles.inputField}>
<label className={styles.loginFormLabel} htmlFor="username">
Username or Email Address
</label>
Expand All @@ -66,7 +82,7 @@
}}
/>
</div>
<div>
<div className={styles.inputField}>
<label className={styles.loginFormLabel} htmlFor="password">
Password
</label>
Expand All @@ -82,12 +98,25 @@
}}
/>
</div>
<div>
<ReCAPTCHA
ref={recaptcha}
sitekey={import.meta.env.VITE_SERVER_SITE_KEY as string}
onChange={() => {
setShowCaptchaError(false);
}}
/>
</div>

{showError && (
<div className={styles.loginError}>
Sorry, we are having trouble logging you in. Please check that Username and Password
are correct.
</div>
)}
{showCaptchaError && (
<div className={styles.loginError}>Please verify the reCAPTCHA</div>
)}
<input
className={`${styles.loginFormSubmit} ${isLoginLoading && styles.loading}`}
type="submit"
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { Application } from "./Application.tsx";
import { Candidates } from "./Candidates.tsx";
import { Login } from "./Login.tsx";
import { PrescreeningForm } from "./PrescreeningForm.tsx";
import { TestCongratulations } from "./TestCongratulations.tsx";
import { TestModals } from "./TestModals.tsx";
import { ThankyouForApplying } from "./ThankyouForApplying.tsx";
export {
Application,
Candidates,
TestCongratulations,
ThankyouForApplying,
PrescreeningForm,
Login,
TestModals,
};
export { Application, Candidates, ThankyouForApplying, PrescreeningForm, Login, TestModals };
5 changes: 5 additions & 0 deletions frontend/src/stylesheets/Login.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
display: flex;
flex-direction: column;
gap: 1.25rem;
align-items: center;
}

.loginHeader {
Expand All @@ -70,6 +71,10 @@
border-radius: 0.25rem;
}

.inputField {
width: 100%;
}

.loginFormSubmit {
padding: 0.75rem 0;
background-color: var(--color-ccidc-red);
Expand Down
129 changes: 129 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"react-google-recaptcha": "^3.1.0"
},
"devDependencies": {
"@types/react-google-recaptcha": "^2.1.9"
}
}
Loading