Merged PR 2295: resolved lint warnings
resolved lint warnings Related work items: #22873
This commit is contained in:
+28
-25
@@ -7,7 +7,7 @@ import Footer from "../../components/footer";
|
||||
import Header from "../../components/header";
|
||||
import ServiceBanner from "../../components/servicebanner";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
|
||||
const SignIn = (props) => {
|
||||
let { t, lang } = useTranslation();
|
||||
@@ -20,7 +20,7 @@ const SignIn = (props) => {
|
||||
const [formData, setFormData] = useState({
|
||||
email: query.email || "",
|
||||
callbackUrl: "",
|
||||
csrfToken: "",
|
||||
csrfToken: ""
|
||||
});
|
||||
|
||||
const [submitForm, setSubmitForm] = useState(false);
|
||||
@@ -54,23 +54,26 @@ const SignIn = (props) => {
|
||||
// }, 500); // Short delay to ensure form is populated before submission
|
||||
// };
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
setButtonDisabled(true); // Disable the submit button to avoid multiple submissions
|
||||
const handleSubmit = useCallback(
|
||||
async (event) => {
|
||||
event.preventDefault();
|
||||
setButtonDisabled(true); // Disable the submit button to avoid multiple submissions
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/auth/signin/emailAPI", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(formData),
|
||||
});
|
||||
try {
|
||||
const res = await fetch("/api/auth/signin/emailAPI", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(formData)
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
setResponse(data); // Update response state
|
||||
} catch (error) {
|
||||
console.error("Error submitting the form:", error);
|
||||
}
|
||||
};
|
||||
const data = await res.json();
|
||||
setResponse(data); // Update response state
|
||||
} catch (error) {
|
||||
console.error("Error submitting the form:", error);
|
||||
}
|
||||
},
|
||||
[formData]
|
||||
);
|
||||
|
||||
// Trigger form submission automatically when data is ready
|
||||
useEffect(() => {
|
||||
@@ -79,7 +82,7 @@ const SignIn = (props) => {
|
||||
setFormData((prevState) => ({
|
||||
...prevState,
|
||||
csrfToken: csrfToken,
|
||||
callbackUrl: callbackUrl || prevState.callbackUrl, // Ensure callback URL is set
|
||||
callbackUrl: callbackUrl || prevState.callbackUrl // Ensure callback URL is set
|
||||
}));
|
||||
}
|
||||
}, [query.email, csrfToken, callbackUrl, response]);
|
||||
@@ -89,7 +92,7 @@ const SignIn = (props) => {
|
||||
if (formData.email && formData.csrfToken && !response) {
|
||||
handleSubmit(new Event("submit"));
|
||||
}
|
||||
}, [formData, response]);
|
||||
}, [formData, response, handleSubmit]);
|
||||
|
||||
// Handle redirection after form submission based on response
|
||||
useEffect(() => {
|
||||
@@ -231,8 +234,8 @@ export async function getServerSideProps(context) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/403", // custom "Access Denied" page
|
||||
permanent: false,
|
||||
},
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -240,8 +243,8 @@ export async function getServerSideProps(context) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/status",
|
||||
permanent: false,
|
||||
},
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -250,7 +253,7 @@ export async function getServerSideProps(context) {
|
||||
"\n//////////////////////\n",
|
||||
"Sign in callbackurl: " + context.req.headers.host,
|
||||
context.locale,
|
||||
csrfToken + "\n//////////////////////\n",
|
||||
csrfToken + "\n//////////////////////\n"
|
||||
);
|
||||
let formURL = context.req.headers.host;
|
||||
console.log("formUrl:", formURL);
|
||||
@@ -279,7 +282,7 @@ export async function getServerSideProps(context) {
|
||||
url.search = params.toString();
|
||||
|
||||
return {
|
||||
props: { csrfToken: csrfToken, callbackUrl: url.toString() },
|
||||
props: { csrfToken: csrfToken, callbackUrl: url.toString() }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user