diff --git a/src/roles/guest/PublicRoutes.jsx b/src/roles/guest/PublicRoutes.jsx
index 4f7a6f9..3ab5d58 100644
--- a/src/roles/guest/PublicRoutes.jsx
+++ b/src/roles/guest/PublicRoutes.jsx
@@ -9,6 +9,7 @@ import HomePage from './landing_page/views/Home';
import LoginPage from './auth/views/Login';
import RegisterPage from './auth/views/Register';
import ForgotPage from './auth/views/ForgotPass';
+import ValidateEmail from './auth/views/ValidateEmail';
function PublicRoutes() {
return(
@@ -22,6 +23,7 @@ function PublicRoutes() {
} />
} />
} />
+ } />
)
diff --git a/src/roles/guest/auth/hooks/useRegister.jsx b/src/roles/guest/auth/hooks/useRegister.jsx
index 34da1c8..6bbd77a 100644
--- a/src/roles/guest/auth/hooks/useRegister.jsx
+++ b/src/roles/guest/auth/hooks/useRegister.jsx
@@ -37,7 +37,7 @@ const useRegister = () => {
await authService.register(roleEndpoint, data);
- navigate('/login');
+ navigate('/validate-email');
} catch (err) {
setError(err.message || 'Registration failed');
} finally {
diff --git a/src/roles/guest/auth/hooks/useValidate.jsx b/src/roles/guest/auth/hooks/useValidate.jsx
new file mode 100644
index 0000000..7dbfbcf
--- /dev/null
+++ b/src/roles/guest/auth/hooks/useValidate.jsx
@@ -0,0 +1,22 @@
+import { useState } from 'react';
+import authService from '../services/authService';
+
+const useValidate = () => {
+ const [error, setError] = useState(null);
+
+ const validateEmail = async (token) => {
+ setError(null);
+ try {
+ const validating = await authService.validateEmail(token);
+ window.location.href = '/login';
+ } catch (err) {
+ setError(err.message);
+ }
+ };
+
+ return {
+ validateEmail,error
+ };
+};
+
+export default useValidate;
diff --git a/src/roles/guest/auth/services/authService.jsx b/src/roles/guest/auth/services/authService.jsx
index 5dd7dc2..3d96c8e 100644
--- a/src/roles/guest/auth/services/authService.jsx
+++ b/src/roles/guest/auth/services/authService.jsx
@@ -58,9 +58,19 @@ const logout = () => {
localStorage.removeItem('token');
};
+const validateEmail = async (token) => {
+ try {
+ const response = await axios.post(`${API_URL}/validateEmail`, { token });
+ return response.data;
+ } catch (error) {
+ throw new Error(error.response?.data?.message || 'Failed Validate');
+ }
+};
+
export default {
login,
register,
forgotPassword,
logout,
+ validateEmail
};
diff --git a/src/roles/guest/auth/views/ValidateEmail.jsx b/src/roles/guest/auth/views/ValidateEmail.jsx
new file mode 100644
index 0000000..a048dc5
--- /dev/null
+++ b/src/roles/guest/auth/views/ValidateEmail.jsx
@@ -0,0 +1,51 @@
+import React, { useEffect, useState } from 'react';
+import { useLocation } from 'react-router-dom';
+import loader from '../../../../assets/images/loading.gif';
+import errorImg from '../../../../assets/images//illustration/IllustrationForgot.png';
+import checkEmail from '../../../../assets/images//illustration/emptyStudent.png';
+import useValidate from '../hooks/useValidate';
+
+const ValidateEmail = () => {
+ const { validateEmail, error } = useValidate();
+ const [ isTokenAvailable, setIsTokenAvailable ] = useState(true);
+ const useQuery = () => {
+ return new URLSearchParams(useLocation().search);
+ };
+
+ const token = useQuery().get('token');
+
+ useEffect(() => {
+ if (token) {
+ validateEmail(token);
+ console.log('good');
+ } else {
+ console.log('No token found in the URL.');
+ setIsTokenAvailable(false);
+ }
+ }, [token]);
+
+ return (
+ <>
+ {isTokenAvailable ?(
+ error ?(
+
+

+
{error}
+
+ ):(
+
+

+
Validating....
+
+ )
+ ):(
+
+

+
check your email for validation
+
+ )}
+ >
+ );
+};
+
+export default ValidateEmail;