mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-31 01:36:23 +02:00
♻️ Require auth for self hosters with app router (#938)
This commit is contained in:
parent
acb55d9c45
commit
1c849eac77
1 changed files with 28 additions and 0 deletions
|
@ -1,6 +1,34 @@
|
|||
"use client";
|
||||
import { signIn, useSession } from "next-auth/react";
|
||||
import React from "react";
|
||||
|
||||
import { StandardLayout } from "@/components/layouts/standard-layout";
|
||||
import { isSelfHosted } from "@/utils/constants";
|
||||
|
||||
const Auth = ({ children }: { children: React.ReactNode }) => {
|
||||
const session = useSession();
|
||||
const isAuthenticated = !!session.data?.user.email;
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
signIn();
|
||||
}
|
||||
}, [isAuthenticated]);
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
if (isSelfHosted) {
|
||||
return (
|
||||
<Auth>
|
||||
<StandardLayout>{children}</StandardLayout>
|
||||
</Auth>
|
||||
);
|
||||
}
|
||||
return <StandardLayout>{children}</StandardLayout>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue