⚡️ ⚡️ add - ajout d'une page mon compte connecter a la bdd + API + routes
This commit is contained in:
1 parent
ae437a097b
commit
38159b90c1
12 files changed
+303
-16
No files matched your search
@@ -16,12 +16,12 @@ const options = {
|
||||
clientId: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
authorization: 'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code',
|
||||
}),
|
||||
EmailProvider({
|
||||
server: process.env.EMAIL_SERVER,
|
||||
from: process.env.EMAIL_FROM,
|
||||
}),
|
||||
}),
|
||||
EmailProvider({
|
||||
server: process.env.EMAIL_SERVER,
|
||||
from: process.env.EMAIL_FROM,
|
||||
}),
|
||||
],
|
||||
adapter: PrismaAdapter(prisma),
|
||||
secret: process.env.SECRET,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import prisma from '../../../lib/prisma'
|
||||
import { getSession } from 'next-auth/react'
|
||||
|
||||
|
||||
// UPDATE /api/profile
|
||||
// Required fields in body: title
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { bioValue } = req.body;
|
||||
const session = await getSession({ req });
|
||||
|
||||
if (req.method === "PUT") {
|
||||
if (session) {
|
||||
const updateUserProfil = await prisma.user.update({
|
||||
where: { email: session.user.email },
|
||||
data: {
|
||||
profile: {
|
||||
update: {
|
||||
bio: bioValue,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
res.status(200).send({ result: updateUserProfil, message: 'Profiled updated !' });
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
`The HTTP ${req.method} method is not supported at this route.`
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user