Merge pull request #685 from getmaxun/email-valid
feat: validate credentials
This commit is contained in:
@@ -33,6 +33,14 @@ router.post("/register", async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(email)) {
|
||||||
|
return res.status(400).json({
|
||||||
|
error: "VALIDATION_ERROR",
|
||||||
|
code: "register.validation.invalid_email_format"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!password || password.length < 6) {
|
if (!password || password.length < 6) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error: "VALIDATION_ERROR",
|
error: "VALIDATION_ERROR",
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ const Login = () => {
|
|||||||
|
|
||||||
const submitForm = async (e: any) => {
|
const submitForm = async (e: any) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (!email.includes("@")) {
|
||||||
|
notify("error", "Please enter a valid email.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.post(
|
const { data } = await axios.post(
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { useThemeMode } from "../context/theme-provider";
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import i18n from '../i18n';
|
import i18n from '../i18n';
|
||||||
|
|
||||||
|
|
||||||
const Register = () => {
|
const Register = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
@@ -39,6 +38,13 @@ const Register = () => {
|
|||||||
|
|
||||||
const submitForm = async (e: any) => {
|
const submitForm = async (e: any) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(email)) {
|
||||||
|
notify("error", "Invalid email format");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.post(`${apiUrl}/auth/register`, { email, password });
|
const { data } = await axios.post(`${apiUrl}/auth/register`, { email, password });
|
||||||
@@ -68,7 +74,6 @@ const Register = () => {
|
|||||||
mt: 6,
|
mt: 6,
|
||||||
padding: 4,
|
padding: 4,
|
||||||
backgroundColor: darkMode ? "#121212" : "#ffffff",
|
backgroundColor: darkMode ? "#121212" : "#ffffff",
|
||||||
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
@@ -80,7 +85,8 @@ const Register = () => {
|
|||||||
color: darkMode ? "#ffffff" : "#333333",
|
color: darkMode ? "#ffffff" : "#333333",
|
||||||
padding: 6,
|
padding: 6,
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
boxShadow: "0px 20px 40px rgba(0, 0, 0, 0.2), 0px -5px 10px rgba(0, 0, 0, 0.15)",
|
boxShadow:
|
||||||
|
"0px 20px 40px rgba(0, 0, 0, 0.2), 0px -5px 10px rgba(0, 0, 0, 0.15)",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
@@ -143,7 +149,11 @@ const Register = () => {
|
|||||||
t('register.button')
|
t('register.button')
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<Typography variant="body2" align="center" sx={{ color: darkMode ? "#ffffff" : "#333333" }}>
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
align="center"
|
||||||
|
sx={{ color: darkMode ? "#ffffff" : "#333333" }}
|
||||||
|
>
|
||||||
{t('register.register_prompt')}{" "}
|
{t('register.register_prompt')}{" "}
|
||||||
<Link to="/login" style={{ textDecoration: "none", color: "#ff33cc" }}>
|
<Link to="/login" style={{ textDecoration: "none", color: "#ff33cc" }}>
|
||||||
{t('register.login_link')}
|
{t('register.login_link')}
|
||||||
|
|||||||
Reference in New Issue
Block a user