code refactoring + many security/bug fixes
This commit is contained in:
+20
-13
@@ -16,17 +16,29 @@ export default function AuthRedirect({ children }: Props) {
|
||||
const [redirect, setRedirect] = useState(true);
|
||||
const { account } = useAccountStore();
|
||||
|
||||
const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER;
|
||||
const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true";
|
||||
const stripeEnabled = process.env.NEXT_PUBLIC_STRIPE === "true";
|
||||
|
||||
useInitialData();
|
||||
|
||||
useEffect(() => {
|
||||
if (!router.pathname.startsWith("/public")) {
|
||||
if (
|
||||
status === "authenticated" &&
|
||||
account.id &&
|
||||
!account.subscription?.active &&
|
||||
stripeEnabled
|
||||
) {
|
||||
router.push("/subscribe").then(() => {
|
||||
setRedirect(false);
|
||||
});
|
||||
}
|
||||
// Redirect to "/choose-username" if user is authenticated and is either a subscriber OR subscription is undefiend, and doesn't have a username
|
||||
else if (
|
||||
emailEnabled &&
|
||||
status === "authenticated" &&
|
||||
(data.user.isSubscriber === true ||
|
||||
data.user.isSubscriber === undefined) &&
|
||||
account.subscription?.active &&
|
||||
stripeEnabled &&
|
||||
account.id &&
|
||||
!account.username
|
||||
) {
|
||||
@@ -35,21 +47,16 @@ export default function AuthRedirect({ children }: Props) {
|
||||
});
|
||||
} else if (
|
||||
status === "authenticated" &&
|
||||
data.user.isSubscriber === false
|
||||
) {
|
||||
router.push("/subscribe").then(() => {
|
||||
setRedirect(false);
|
||||
});
|
||||
} else if (
|
||||
status === "authenticated" &&
|
||||
account.id &&
|
||||
(router.pathname === "/login" ||
|
||||
router.pathname === "/register" ||
|
||||
router.pathname === "/confirmation" ||
|
||||
router.pathname === "/subscribe" ||
|
||||
router.pathname === "/choose-username" ||
|
||||
router.pathname === "/forgot")
|
||||
router.pathname === "/forgot" ||
|
||||
router.pathname === "/")
|
||||
) {
|
||||
router.push("/").then(() => {
|
||||
router.push("/dashboard").then(() => {
|
||||
setRedirect(false);
|
||||
});
|
||||
} else if (
|
||||
@@ -69,7 +76,7 @@ export default function AuthRedirect({ children }: Props) {
|
||||
} else {
|
||||
setRedirect(false);
|
||||
}
|
||||
}, [status, account]);
|
||||
}, [status, account, router.pathname]);
|
||||
|
||||
if (status !== "loading" && !redirect) return <>{children}</>;
|
||||
else return <></>;
|
||||
|
||||
@@ -10,10 +10,20 @@ interface Props {
|
||||
|
||||
export default function CenteredForm({ text, children }: Props) {
|
||||
const { theme } = useTheme();
|
||||
|
||||
return (
|
||||
<div className="absolute top-0 bottom-0 left-0 right-0 flex justify-center items-center p-5">
|
||||
<div className="m-auto flex flex-col gap-2 w-full">
|
||||
{theme === "dark" ? (
|
||||
{theme ? (
|
||||
<Image
|
||||
src={`/linkwarden_${theme === "dark" ? "dark" : "li"}.png`}
|
||||
width={640}
|
||||
height={136}
|
||||
alt="Linkwarden"
|
||||
className="h-12 w-fit mx-auto"
|
||||
/>
|
||||
) : undefined}
|
||||
{/* {theme === "dark" ? (
|
||||
<Image
|
||||
src="/linkwarden_dark.png"
|
||||
width={640}
|
||||
@@ -29,7 +39,7 @@ export default function CenteredForm({ text, children }: Props) {
|
||||
alt="Linkwarden"
|
||||
className="h-12 w-fit mx-auto"
|
||||
/>
|
||||
)}
|
||||
)} */}
|
||||
{text ? (
|
||||
<p className="text-lg max-w-[30rem] min-w-80 w-full mx-auto font-semibold text-black dark:text-white px-2 text-center">
|
||||
{text}
|
||||
|
||||
@@ -93,11 +93,14 @@ export default function LinkLayout({ children }: Props) {
|
||||
</div> */}
|
||||
|
||||
<div
|
||||
onClick={() => router.back()}
|
||||
onClick={() => router.push(`/collections/${linkCollection?.id}`)}
|
||||
className="inline-flex gap-1 hover:opacity-60 items-center select-none cursor-pointer p-2 lg:p-0 lg:px-1 lg:my-2 text-gray-500 dark:text-gray-300 rounded-md duration-100"
|
||||
>
|
||||
<FontAwesomeIcon icon={faChevronLeft} className="w-4 h-4" />
|
||||
Back
|
||||
Back{" "}
|
||||
<span className="hidden sm:inline-block">
|
||||
to <span className="capitalize">{linkCollection?.name}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="lg:hidden">
|
||||
|
||||
Reference in New Issue
Block a user