forked from digitomize/digitomize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'digitomize:main' into readme-dev
- Loading branch information
Showing
13 changed files
with
297 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.