mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 15:35:35 +00:00
Début ajout modal ajout catégories
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
import '../styles/globals.scss';
|
||||
import { SessionProvider } from 'next-auth/react';
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />;
|
||||
function MyApp({
|
||||
Component,
|
||||
pageProps: { session, ...pageProps }
|
||||
}) {
|
||||
return (
|
||||
<SessionProvider session={session}>
|
||||
<Component {...pageProps} />
|
||||
</SessionProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
48
pages/api/auth/[...nextauth].js
Normal file
48
pages/api/auth/[...nextauth].js
Normal file
@@ -0,0 +1,48 @@
|
||||
import NextAuth from 'next-auth'
|
||||
import CredentialsProvider from 'next-auth/providers/credentials';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export default NextAuth({
|
||||
providers: [
|
||||
CredentialsProvider({
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
username: { label: 'Email', type: 'text', placeholder: 'user@example.com' },
|
||||
password: { label: 'Mot de passe', type: 'password', placeholder: '********' }
|
||||
},
|
||||
async authorize(credentials, req) {
|
||||
return { email: 'user@example.com' };
|
||||
|
||||
const email = credentials?.email;
|
||||
const password = credentials?.password;
|
||||
|
||||
if (!email || !password)
|
||||
return null;
|
||||
|
||||
let user;
|
||||
try {
|
||||
user = await prisma.user.findUnique({
|
||||
where: { email }
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Impossible de récupérer l'utilisateur avec les identifiants : ${credentials}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!user)
|
||||
return null;
|
||||
|
||||
const passwordMatch = await bcrypt.compare(password, user.password);
|
||||
if (!passwordMatch)
|
||||
return null;
|
||||
|
||||
return {
|
||||
email: user.email
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
@@ -1,14 +1,16 @@
|
||||
import { createRef, useRef, useState } from 'react';
|
||||
import { useSession } from 'next-auth/react';
|
||||
|
||||
import Categories from '../components/Categories/Categories';
|
||||
import Links from '../components/Links/Links';
|
||||
|
||||
import styles from '../styles/Home.module.scss';
|
||||
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
const prisma = new PrismaClient()
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export default function Home({ categories, favorites }) {
|
||||
const { data: session, status } = useSession();
|
||||
const [categoryActive, setCategoryActive] = useState(categories?.[0]?.id);
|
||||
const refCategoryActive = useRef();
|
||||
|
||||
@@ -21,6 +23,7 @@ export default function Home({ categories, favorites }) {
|
||||
behavior: 'smooth'
|
||||
});
|
||||
}
|
||||
console.log(session, session?.user);
|
||||
|
||||
return (
|
||||
<div className={styles.App}>
|
||||
@@ -29,11 +32,13 @@ export default function Home({ categories, favorites }) {
|
||||
favorites={favorites}
|
||||
handleSelectCategory={handleSelectCategory}
|
||||
categoryActive={categoryActive}
|
||||
session={session}
|
||||
/>
|
||||
<Links
|
||||
categories={categories}
|
||||
setCategoryActive={setCategoryActive}
|
||||
refCategoryActive={refCategoryActive}
|
||||
session={session}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user