From 3fbc296c7ac67c241fcc5c325a7d56984015de08 Mon Sep 17 00:00:00 2001 From: StephDietz Date: Wed, 20 Sep 2023 12:23:24 -0500 Subject: [PATCH] add SessionProvider --- dashboard/15-final/app/Providers.tsx | 7 +++++++ dashboard/15-final/app/api/auth/[...nextauth]/route.ts | 8 ++++---- dashboard/15-final/app/layout.tsx | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 dashboard/15-final/app/Providers.tsx diff --git a/dashboard/15-final/app/Providers.tsx b/dashboard/15-final/app/Providers.tsx new file mode 100644 index 00000000..857fa05b --- /dev/null +++ b/dashboard/15-final/app/Providers.tsx @@ -0,0 +1,7 @@ +'use client'; + +import { SessionProvider } from 'next-auth/react'; + +export const AuthProvider = ({ children }) => { + return {children}; +}; diff --git a/dashboard/15-final/app/api/auth/[...nextauth]/route.ts b/dashboard/15-final/app/api/auth/[...nextauth]/route.ts index 040cb31b..8ba81784 100644 --- a/dashboard/15-final/app/api/auth/[...nextauth]/route.ts +++ b/dashboard/15-final/app/api/auth/[...nextauth]/route.ts @@ -1,10 +1,10 @@ -import NextAuth from 'next-auth/next'; +import NextAuth from 'next-auth'; import CredentialsProvider from 'next-auth/providers/credentials'; import bcrypt from 'bcrypt'; import { fetchUser } from '../../../lib/data'; import { User } from '@/app/lib/definitions'; -export const authOptions = { +const authOptions = { providers: [ CredentialsProvider({ name: 'credentials', @@ -18,7 +18,7 @@ export const authOptions = { try { const user = await fetchUser(email); - console.log('user: ', user); + if (!user) { return null; } @@ -48,4 +48,4 @@ export const authOptions = { const handler = NextAuth(authOptions); -export { handler as GET, handler as POST }; +export { handler as GET, handler as POST, authOptions }; diff --git a/dashboard/15-final/app/layout.tsx b/dashboard/15-final/app/layout.tsx index 43a3e243..1aca2604 100644 --- a/dashboard/15-final/app/layout.tsx +++ b/dashboard/15-final/app/layout.tsx @@ -1,6 +1,7 @@ import './global.css'; import type { Metadata } from 'next'; import { Inter } from 'next/font/google'; +import { AuthProvider } from './Providers'; const inter = Inter({ subsets: ['latin'] }); @@ -16,7 +17,9 @@ export default function RootLayout({ }) { return ( - {children} + + {children} + ); }