add SessionProvider

This commit is contained in:
StephDietz
2023-09-20 12:23:24 -05:00
parent 5a6d8a8812
commit 3fbc296c7a
3 changed files with 15 additions and 5 deletions

View File

@@ -0,0 +1,7 @@
'use client';
import { SessionProvider } from 'next-auth/react';
export const AuthProvider = ({ children }) => {
return <SessionProvider>{children}</SessionProvider>;
};

View File

@@ -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 };

View File

@@ -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 (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<AuthProvider>{children}</AuthProvider>
</body>
</html>
);
}