diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 689308c..3dcebcc 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,2 +1,3 @@ import { handlers } from "@/auth" // Referring to the auth.ts we just created export const { GET, POST } = handlers + diff --git a/app/layout.tsx b/app/layout.tsx index 3314e47..4d09d53 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import { Inter } from "next/font/google"; import "./globals.css"; +import { SessionProvider } from "next-auth/react"; const inter = Inter({ subsets: ["latin"] }); diff --git a/app/page.tsx b/app/page.tsx index a6f098c..4e1f965 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,22 +1,14 @@ import { getUsers } from "@/drizzle/db"; -import Image from "next/image"; -import avatar from "../public/leverpostej.jpg"; import SignIn from "@/components/SignIn"; +import { auth } from "@/auth"; +import { Session } from "next-auth"; export default async function Home() { const users = await getUsers(); - console.log(users); - const name = users[0] ? users[0].name : "guest"; + const session: Session | null = await auth(); return (
-

Hello {name}!

- {`Picture - +
); } diff --git a/components/SignIn.tsx b/components/SignIn.tsx index ffca685..8a7168c 100644 --- a/components/SignIn.tsx +++ b/components/SignIn.tsx @@ -1,14 +1,31 @@ -import { signIn } from "@/auth" - -export default async function SignIn() { - return ( -
{ - "use server" - await signIn("github") - }} - > - +"use client"; + +import { signIn, signOut } from "next-auth/react"; +import { SyntheticEvent } from "react"; +import { Session } from "next-auth"; + +interface SignInProps { + session: Session | null; +} + +export default async function SignIn({ session }: SignInProps) { + const handleSignIn = async (event: SyntheticEvent) => { + event.preventDefault(); + await signIn("github"); + }; + + const handleSignOut = async (event: SyntheticEvent) => { + event.preventDefault(); + await signOut(); + }; + + return session?.user ? ( + +
- ) -} \ No newline at end of file + ) : ( +
+ +
+ ); +} diff --git a/package-lock.json b/package-lock.json index 53076f7..45ae101 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "dependencies": { "@next/env": "^14.2.3", + "@types/next-auth": "^3.15.0", "@vercel/postgres": "^0.8.0", "drizzle-orm": "^0.30.10", "next": "14.2.3", @@ -1327,6 +1328,15 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/next-auth": { + "version": "3.15.0", + "resolved": "https://registry.npmjs.org/@types/next-auth/-/next-auth-3.15.0.tgz", + "integrity": "sha512-ZVfejlu81YiIRX1m0iKAfvZ3nK7K9EyZWhNARNKsFop8kNAgEvMnlKpTpwN59xkK2OhyWLagPuiDAVBYSO9jSA==", + "deprecated": "This is a stub types definition. next-auth provides its own type definitions, so you do not need this installed.", + "dependencies": { + "next-auth": "*" + } + }, "node_modules/@types/node": { "version": "20.12.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.12.tgz", diff --git a/package.json b/package.json index 9f81875..d277c12 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@next/env": "^14.2.3", + "@types/next-auth": "^3.15.0", "@vercel/postgres": "^0.8.0", "drizzle-orm": "^0.30.10", "next": "14.2.3",