Skip to content

Commit

Permalink
added prisma query to update location
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutlope committed Mar 25, 2023
1 parent 12cd915 commit 9909381
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pages/api/remaining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ export default async function handler(
if (!user?.location) {
const ip = requestIp.getClientIp(req);
const location = await fetch(
`http://api.ipstack.com/${ip}?access_key=31ad79df45feb22c2e29e3f92c6455e4`
`http://api.ipstack.com/${ip}?access_key=${process.env.IPSTACK_API_KEY}`
).then((res) => res.json());

console.log({ ip, location });
// await prisma.user.update({
// where: {
// email: session.user.email!,
// },
// data: {
// location: location.country_name,
// },
// });
await prisma.user.update({
where: {
email: session.user.email!,
},
data: {
location: location.country_code,
},
});

console.log("Updated user location");
}

return res.status(200).json({ remainingGenerations: user?.credits });
Expand Down

0 comments on commit 9909381

Please sign in to comment.