Files
formbricks/apps/web/components/layout/WithAuthentication.tsx
Matti Nannt 5c378bc8ce Feature/monorepo #95 (#105)
Move repository into a monorepo with turborepo and pnpm.
This is a big change in the way the code is organized, used and deployed.
2022-10-13 09:46:43 +02:00

22 lines
490 B
TypeScript

import { signIn, useSession } from "next-auth/react";
import Loading from "../Loading";
const withAuthentication = (Component) =>
function WithAuth(props) {
const { status } = useSession({
required: true,
onUnauthenticated() {
// The user is not authenticated, handle it here.
return signIn();
},
});
if (status === "loading") {
return <Loading />;
}
return <Component {...props} />;
};
export default withAuthentication;