Skip to content

Commit

Permalink
Merge branch 'digitomize:main' into readme-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
RamakrushnaBiswal authored Jun 4, 2024
2 parents 51f9762 + 4d8e8a8 commit b3c87fe
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,15 @@
"contributions": [
"doc"
]
},
{
"login": "Ajen07",
"name": "Arman Kumar Jena",
"avatar_url": "https://avatars.githubusercontent.com/u/112967686?v=4",
"profile": "https://github.com/Ajen07",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Digitomize**, part of **Microsoft for Startups Founders Hub**, is an open-source platform that combines two main sections: Contests and User Profiles. It allows users to explore upcoming coding contests and dynamically create developer portfolios. </br>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-83-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-84-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
Website: [![Better Stack Badge](https://uptime.betterstack.com/status-badges/v1/monitor/zb9g.svg)](https://uptime.betterstack.com/?utm_source=status_badge)

Expand Down Expand Up @@ -257,6 +257,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://keshavpriyam.vercel.app/"><img src="https://avatars.githubusercontent.com/u/95236968?v=4?s=100" width="100px;" alt="Keshav Priyam"/><br /><sub><b>Keshav Priyam</b></sub></a><br /><a href="https://github.com/digitomize/digitomize/commits?author=kshavp" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RamakrushnaBiswal"><img src="https://avatars.githubusercontent.com/u/125277258?v=4?s=100" width="100px;" alt="Ramakrushna Biswal"/><br /><sub><b>Ramakrushna Biswal</b></sub></a><br /><a href="https://github.com/digitomize/digitomize/commits?author=RamakrushnaBiswal" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RohittCodes"><img src="https://avatars.githubusercontent.com/u/104308198?v=4?s=100" width="100px;" alt="Rohith Singh"/><br /><sub><b>Rohith Singh</b></sub></a><br /><a href="https://github.com/digitomize/digitomize/commits?author=RohittCodes" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Ajen07"><img src="https://avatars.githubusercontent.com/u/112967686?v=4?s=100" width="100px;" alt="Arman Kumar Jena"/><br /><sub><b>Arman Kumar Jena</b></sub></a><br /><a href="https://github.com/digitomize/digitomize/commits?author=Ajen07" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
14 changes: 14 additions & 0 deletions backend/users/middlewares/authMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ const addUID = async (request, response, next) => {
}

try {
const decodedToken = await getAuth().verifyIdToken(authToken);
const {
uid,
firebase: { sign_in_provider },
} = decodedToken;

if (sign_in_provider === "github.com") {
await getAuth().updateUser(uid, {
emailVerified: true,
});
}
getAuth()
.verifyIdToken(authToken)
.then((decTok) => {
request.decodedToken = decTok;
if (decTok.firebase.sign_in_provider === "github.com") {
decTok.email_verified = true;
}
// console.log("calling next");
next();
})
Expand Down
9 changes: 9 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
About,
Footer,
MetaData,
resendLoader
} from "./components/CustomComponents";
// import UserDashBoardAccount from "./user/dashboard/Account";
import UserDashboard from "./user/dashboard/UserDashboard";
Expand Down Expand Up @@ -117,6 +118,8 @@ import { userDashboardDetails } from "../api";
import Preferences from "./user/dashboard/Preferences/Preferences";
import Ratings from "./user/dashboard/Ratings/Ratings";
import Settings from "./user/dashboard/Settings/Settings";
import ResendEmailVerification from "./pages/verification/ResendEmailVerification";
import VerifyEmailPage from "./pages/verification/VerifyEmailPage";

function Logout() {
const navigate = useNavigate();
Expand Down Expand Up @@ -177,6 +180,12 @@ const router = createBrowserRouter(
<Route path="logout" element={<Logout />} />
<Route path="signup" element={<Signup />} loader={signupLoader} />
<Route path="forgot-password" element={<ForgotPassword />} loader={forgotPasswordLoader} />
<Route
path="resend-email-verification"
element={<ResendEmailVerification />}
loader={resendLoader}
/>
<Route path="user-email-verification" element={<VerifyEmailPage />} />
<Route element={<ContestPageLayout />}>
<Route path="contests" element={<Filter />} />
<Route path="challenges" element={<Challenges />} />
Expand Down
16 changes: 11 additions & 5 deletions client/src/ProtectedRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React from "react";
import { Outlet, Navigate } from "react-router-dom";
import { useUserAuth } from "@context/UserAuthContext";
import { auth } from "../firebase";

function ProtectedRoute() {
const { user } = useUserAuth();
return user ? (
<Outlet />
) : (
<Navigate to="/login?message=Please login first!" />
);

if (!user) {
return <Navigate to="/login?message=Please login first!" />;
}

if (auth?.currentUser?.emailVerified) {
return <Outlet />;
}

return <Navigate to="/resend-email-verification?message=Please verify your email" />;
}

export default ProtectedRoute;
3 changes: 2 additions & 1 deletion client/src/components/AuthButtons/GithubAuthButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default function GithubAuthButton() {
})
// .then((res) => console.log(res))
.catch((err) => console.error(err));
navigate("/u/dashboard/account");
await auth.currentUser.reload()
navigate("/u/dashboard");
})
.catch((error) => {
toast.error(error.code, {
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/CustomComponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Footer from "./globals/Footer";
import { loader as loginLoader } from "./Login";
import { loader as signupLoader } from "./globals/Signup";
import { loader as forgotPasswordLoader } from "./ForgotPassword";
import {loader as resendLoader} from "../pages/verification/ResendEmailVerification"
import NewNavbar from "./globals/Navbar/NewNavbar";
import ScrollToTop from "./globals/ScrollToTop";
import Signup from "./globals/Signup";
Expand Down Expand Up @@ -51,4 +52,5 @@ export {
signupLoader,
ForgotPassword,
forgotPasswordLoader,
resendLoader,
};
3 changes: 2 additions & 1 deletion client/src/components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import { Eye, EyeOff } from "lucide-react";
export async function loader({ request }) {
const message = new URL(request.url).searchParams.get("message");
const loggedIn = await isLoggedIn();

if (loggedIn) {
return redirect("/u/dashboard");
return redirect("/u/dashboard");
}

return message;
Expand Down
15 changes: 14 additions & 1 deletion client/src/components/globals/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export async function loader() {
if (loggedIn) {
return redirect("/login");
}
if (loggedIn && auth.currentUser && auth.currentUser.emailVerified) {
return redirect("/u/dashboard");
}
return null;
}

Expand Down Expand Up @@ -105,7 +108,17 @@ export default function Signup() {

.catch((err) => setError(err.code));
}
navigate("/login");
toast.success("Verification link sent to email", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "colored",
});
navigate("/login", { replace: true });
} catch (err) {
toast.error(err.code, {
position: "top-right",
Expand Down
6 changes: 6 additions & 0 deletions client/src/context/UserAuthContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
signInWithPopup,
GithubAuthProvider,
updateProfile,
sendEmailVerification,
} from "firebase/auth";

import { auth } from "../../firebase";
Expand Down Expand Up @@ -37,6 +38,11 @@ export function UserAuthContextProvider({ children }) {
console.error("Error updating profile:", error);
});
const token = await user.getIdToken();
sendEmailVerification(user).then(() => {
/* console.log("Email verification sent."); */
}).catch((error) => {
console.error("Error sending email verification:", error);
});
return { result, token };
})
.catch((error) => {
Expand Down
92 changes: 92 additions & 0 deletions client/src/pages/verification/ResendEmailVerification.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useState } from "react";
import { toast, ToastContainer } from "react-toastify";
import { auth } from "../../../firebase";
import { sendEmailVerification } from "firebase/auth";
import { isLoggedIn } from "../../../api";
import { redirect } from "react-router-dom";


export async function loader() {
const loggedIn = await isLoggedIn();
if (loggedIn && auth.currentUser.emailVerified) {
return redirect("/u/dashboard");
}else if (!loggedIn ) {
return redirect("/login");
}
return null;
}

const ResendEmailVerification = () => {
const [btnState, setbtnState] = useState(false);
const handleSubmit = async (e) => {
e.preventDefault();
try {
setbtnState(true);
await sendEmailVerification(auth.currentUser);
toast.success("Verification E-Mail send", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "colored",
});
setbtnState(false);
} catch (err) {
setbtnState(false);
toast.error(err.code, {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "colored",
});
}
};
return (
<>
<ToastContainer />


<main className="h-screen flex flex-col items-center justify-center w-fit ml-auto mr-auto gap-y-1 z-30 antialiased relative">
<h2 className="phonesm:text-xl md:text-5xl bg-clip-text text-transparent pb-4 bg-gradient-to-tr from-[#4285f4] to-white font-bold font-sans text-center relative z-10">
Please verify your email to continue
</h2>
<p className="text-neutral-500 text-xl max-w-lg mx-auto my-2 text-center relative z-10">
Didn't receive the verification email? Click the button below to
resend it.
</p>
<div className="">

<div className="w-full flex justify-center px-4 py-4">
<button
type="button"
onClick={handleSubmit}
disabled={btnState}
className="relative inline-flex items-center justify-center px-6 py-2 text-lg font-medium tracking-tighter text-white bg-gray-800 rounded-md group min-w-2/5"
>
<span
className="absolute inset-0 w-full h-full mt-1 ml-1 transition-all duration-300 ease-in-out bg-[#4285f4] rounded-md group-hover:mt-0 group-hover:ml-0"
/>
<span className="absolute inset-0 w-full h-full bg-white rounded-md "/>
<span
className="absolute inset-0 w-full h-full transition-all duration-200 ease-in-out delay-100 bg-[#4285f4] rounded-md opacity-0 group-hover:opacity-100"
/>
<span className="relative text-black transition-colors duration-200 ease-in-out delay-100 group-hover:text-white">
{btnState ? 'Sending...' : 'Resend Email'}
</span>
</button>
</div>

</div>
</main>
</>
);
};

export default ResendEmailVerification;
Loading

0 comments on commit b3c87fe

Please sign in to comment.