Skip to content

Fix/auth UI #1273

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

Merged
merged 3 commits into from
Oct 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
# npx lint-staged
10 changes: 9 additions & 1 deletion src/components/shared/buttons/globalbutton/Button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
color: white;
}

.solid:disabled {
background-color: #ff5b31;
color: white;
cursor: not-allowed;
pointer-events: none;
opacity: 0.5;
}

.outline {
border-radius: 12px;
background-color: white;
Expand All @@ -24,11 +32,11 @@
transition: all 0.2s ease-in-out;
}

.solid:disabled,
.outline:disabled {
color: black;
border: black solid 1px;
cursor: not-allowed;
background-color: #28183b;
opacity: 0.5;
}

Expand Down
29 changes: 26 additions & 3 deletions src/hooks/useAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,40 @@ export function useAuth(authType) {
const navigate = useNavigate();
const [loading, setloading] = useState(false);
const dispatch = useDispatch();
const emailRegex = /^[a-zA-Z0-9._:$!%-]+@[a-zA-Z0-9.-]+.[a-zA-Z]$/;

async function authenticateUser(credentials) {
async function authenticateUser(credentials, setErrors) {
if (!checkInternetConnection()) {
return;
}

if (emailRegex.test(credentials.email) === false) {
setErrors((prev) => ({
...prev,
email: "Please enter a valid email address",
}));
return;
}

// Passwords needs to be minimum 8 characters long with atleast 1 number, 1 uppercase and 1 lowercase letter
const passwordRegex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
if (passwordRegex.test(credentials.password) === false) {
setErrors((prev) => ({
...prev,
password:
"Password must be minimum 8 characters long with atleast 1 number, 1 uppercase and 1 lowercase letter",
}));
return;
}

setloading(true);

const response = await (authType === "login"
const response = await (authType === "signin"
? LoginUser(credentials)
: RegisterUser(credentials));
: RegisterUser({
...credentials,
userType: credentials.userType.value,
}));

if (response?.status === 201 || response?.status === 200) {
showSuccessToast(response?.data?.message);
Expand Down
190 changes: 0 additions & 190 deletions src/pages/auth/Login.jsx

This file was deleted.

Loading
Loading