Get user ID from session instead of looking it up
This commit is contained in:
1 parent
b760ed6ff7
commit
209791d86d
11 files changed
+12
-79
No files matched your search
@@ -11,24 +11,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
|
||||
if (req.method == "PATCH") {
|
||||
// TODO: Add user ID to user session object
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
email: session.user.email,
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
});
|
||||
|
||||
if (!user) { res.status(404).json({message: 'User not found'}); return; }
|
||||
|
||||
const startMins = req.body.start;
|
||||
const endMins = req.body.end;
|
||||
|
||||
const updateDay = await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
id: session.user.id,
|
||||
},
|
||||
data: {
|
||||
startTime: startMins,
|
||||
|
||||
@@ -8,20 +8,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
res.status(401).json({message: "Not authenticated"});
|
||||
return;
|
||||
}
|
||||
// TODO: Add user ID to user session object
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
email: session.user.email,
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
res.status(404).json({message: 'User not found'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method == "PATCH" || req.method == "POST") {
|
||||
|
||||
@@ -37,7 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
if (req.method == "POST") {
|
||||
const createEventType = await prisma.eventType.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
userId: session.user.id,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user