mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-23 12:45:51 +00:00
add SessionProvider
This commit is contained in:
7
dashboard/15-final/app/Providers.tsx
Normal file
7
dashboard/15-final/app/Providers.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { SessionProvider } from 'next-auth/react';
|
||||
|
||||
export const AuthProvider = ({ children }) => {
|
||||
return <SessionProvider>{children}</SessionProvider>;
|
||||
};
|
||||
@@ -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 };
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user