Skip to content

Commit

Permalink
add SessionProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
StephDietz committed Sep 20, 2023
1 parent 5a6d8a8 commit 3fbc296
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions dashboard/15-final/app/Providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client';

import { SessionProvider } from 'next-auth/react';

export const AuthProvider = ({ children }) => {
return <SessionProvider>{children}</SessionProvider>;
};
8 changes: 4 additions & 4 deletions dashboard/15-final/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -18,7 +18,7 @@ export const authOptions = {

try {
const user = await fetchUser(email);
console.log('user: ', user);

if (!user) {
return null;
}
Expand Down Expand Up @@ -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 };
5 changes: 4 additions & 1 deletion dashboard/15-final/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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'] });

Expand All @@ -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>
);
}

0 comments on commit 3fbc296

Please sign in to comment.