Set up auth + corrected local db

This commit is contained in:
2024-11-09 18:41:41 -06:00
parent cb2e59e07e
commit 9c318b4451
6 changed files with 81 additions and 43 deletions

View File

@@ -0,0 +1,24 @@
"use client";
import type { FC, PropsWithChildren } from "react";
import { useSession, signIn, SessionProvider } from "next-auth/react";
export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
return (
<SessionProvider>
<AuthWrapper>{children}</AuthWrapper>
</SessionProvider>
);
};
const AuthWrapper: FC<PropsWithChildren> = ({ children }) => {
const session = useSession();
console.log("SESSION", session);
if (session.status === "unauthenticated") {
void signIn();
}
return children;
};

View File

@@ -5,10 +5,11 @@ import { type Metadata } from "next";
import { TRPCReactProvider } from "~/trpc/react";
import { HydrateClient } from "~/trpc/server";
import { AuthProvider } from "~/app/_components/auth-provider";
export const metadata: Metadata = {
title: "Create T3 App",
description: "Generated by create-t3-app",
title: "ls",
description: "quick note taking application",
icons: [{ rel: "icon", url: "/favicon.ico" }],
};
@@ -19,7 +20,9 @@ export default function RootLayout({
<html lang="en" className={`${GeistSans.variable}`}>
<body>
<TRPCReactProvider>
<HydrateClient>{children}</HydrateClient>
<HydrateClient>
<AuthProvider>{children}</AuthProvider>
</HydrateClient>
</TRPCReactProvider>
</body>
</html>

View File

@@ -1,3 +1,19 @@
import { auth } from "~/server/auth";
export default async function Home() {
return <h1>ls</h1>;
const session = await auth();
if (!session) {
<main>
<h1>Not signed in</h1>
</main>;
}
return (
<main>
<h1>ls</h1>
<pre>
<code>{JSON.stringify(session, undefined, 2)}</code>
</pre>
</main>
);
}