Skip to content

Commit

Permalink
Add Verify Email
Browse files Browse the repository at this point in the history
  • Loading branch information
vegetason committed Oct 7, 2024
1 parent e30941c commit 2a49171
Show file tree
Hide file tree
Showing 6 changed files with 6,569 additions and 3,308 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@types/react-i18next": "^8.1.0",
"@types/react-router": "^5.1.19",
"@types/react-router-dom": "^5.3.3",
"antd": "^5.21.2",
"axios": "^1.1.2",
"bootstrap": "^5.2.2",
"browser": "^0.2.6",
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function SignupForm() {
<AiOutlineCheck className="text-white text-4xl" />
</div>
<div className="text-[#afb1b4] text-lg mb-4 font-inter">
<p>Your account has been succefully created !</p>
<p>Account created, Check your email to verify your account !</p>
</div>
<Link to="/login" ><Button label="Continue" className="w-[80px]" /></Link>
</div>
Expand Down
58 changes: 58 additions & 0 deletions src/pages/verifyEmail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useState, useEffect } from "react";
import { AiOutlineCheck } from "react-icons/ai";
import { Link, useNavigate } from "react-router-dom";
import { verifyEmailAction } from "../redux/actions/verifyEmailAction";
import { Spin } from "antd";
import Button from "../components/form/Button";

const VerifyEmail = () => {
const [loading, setLoading] = useState(true);
const navigate = useNavigate();

useEffect(() => {
async function verify() {
try {
const response = await verifyEmailAction();


if (!response?.data?.data?.verifyUser?.isVerified) {
navigate("/login");
}
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
}

verify();
}, [navigate]);


if (loading) {
return (
<div className="flex items-center justify-center h-screen">
<Spin size="large" />
</div>
);
}


return <>
<div className="flex items-center justify-center mx-auto bg-[#374151] h-screen">
<div className="bg-[#1F2A37] w-[30vw] flex h-[70vh] flex-col items-center justify-center rounded-sm sm:w-5/6 lg:w-[45vw]">
<div
className={`rounded-full flex items-center justify-center p-4 mx-auto mb-4`}
>
<AiOutlineCheck className="text-white text-4xl" />
</div>
<div className="text-[#afb1b4] text-lg mb-4 font-inter">
<p>Your account has been succefully verified !</p>
</div>
<Link to="/login" ><Button label="Continue" className="w-[80px]" /></Link>
</div>
</div>
</>
};

export default VerifyEmail;
35 changes: 35 additions & 0 deletions src/redux/actions/verifyEmailAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import jwtDecode from "jwt-decode";
import axios from "./axiosconfig";
import { toast } from "react-toastify";

export const verifyEmailAction = async() => {
try {
const hash = window.location.hash;

const params = new URLSearchParams(hash.split('?')[1]);

const token = params.get('token') as any;
const decoded: any = await jwtDecode(token);
const UserId = decoded.data._id
const response = await axios.post("/",{
query: `
mutation Mutation($id: ID!) {
verifyUser(ID: $id) {
id
email
isVerified
}
}
`, variables: {
id:`${UserId}`
}
})

return response;

} catch (error: any) {
toast.error("An error Occured during verification")
return error;

}
}
2 changes: 2 additions & 0 deletions src/routes/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import ApplicationDetails from "../pages/Applications/ViewSingleApplication";
import Dashboard from "../pages/Dashboard";
import ApplicantLayout from "../pages/Applicant/ApplicantLayout";
import AdminLayout from "../components/Layout/Admins/AdminLayout";
import VerifyEmail from "../pages/verifyEmail";

function Navigation() {
const roleName = localStorage.getItem("roleName");
Expand All @@ -49,6 +50,7 @@ function Navigation() {
<Route path="/test_tailwind" element={<TestTailwind />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/signup" element={<SignupForm />} />
<Route path="/verifyEmail" element={<VerifyEmail/>}/>
<Route path="/admin" element={<AdminLayout />}>
<Route index element={<PrivateRoute><Dashboard /></PrivateRoute>} />
<Route
Expand Down
Loading

0 comments on commit 2a49171

Please sign in to comment.