Skip to content

Commit

Permalink
Merge pull request #46 from gnmyt/fixes/misleading-message
Browse files Browse the repository at this point in the history
🐛 Fix misleading sign-up message
  • Loading branch information
gnmyt authored Sep 3, 2024
2 parents fdc691e + 791f043 commit ca73c84
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions client/src/common/components/LoginDialog/LoginDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,25 @@ export const LoginDialog = ({ open }) => {
const { updateSessionToken, firstTimeSetup } = useContext(UserContext);

const createAccountFirst = async () => {
let resultObj;
try {
resultObj = await request("accounts/register", "POST", { username, password, firstName, lastName });
await request("accounts/register", "POST", { username, password, firstName, lastName });

if (resultObj.code) throw new Error(resultObj.message);
return true;
} catch (error) {
if (error.message.toString().includes("^(?=.*[0-9])")) {
setError("Password must contain at least one number and one special character");
return false;
}

setError(error.message || "An error occurred");
return;
return false;
}
}

const submit = async (event) => {
event.preventDefault();

if (firstTimeSetup) await createAccountFirst();
if (firstTimeSetup && !await createAccountFirst()) return;

let resultObj;
try {
Expand All @@ -60,7 +64,7 @@ export const LoginDialog = ({ open }) => {

useEffect(() => {
setError("");
}, [username, password, code]);
}, [username, firstName, lastName, password, code]);

return (
<DialogProvider disableClosing open={open}>
Expand Down

0 comments on commit ca73c84

Please sign in to comment.