Skip to content

Commit

Permalink
Merge pull request #34 from evmiguel/remove-email-prop
Browse files Browse the repository at this point in the history
Remove email prop and use session provider in api
  • Loading branch information
evmiguel authored Apr 8, 2024
2 parents 44c21f4 + 0519331 commit f46501c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
7 changes: 6 additions & 1 deletion app/api/purchase/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import prisma from "@/lib/prisma";
import { NextRequest, NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "../auth/[...nextauth]/options";

// @ts-ignore
BigInt.prototype.toJSON = function () {
Expand All @@ -8,7 +10,10 @@ BigInt.prototype.toJSON = function () {

export async function POST(request: NextRequest) {
const res = await request.json();
const { email, name, cost, category, date } = res;
const { name, cost, category, date } = res;

const session = await getServerSession(authOptions);
const email = session?.user?.email;
const user = await prisma.user.findFirst({
where: {
email
Expand Down
2 changes: 1 addition & 1 deletion app/purchases/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default async function Page() {
<Sidebar className={"flex space-x-4 pt-10 justify-center md:order-2 md:space-x-0 md:block md:w-50 md:col-span-1 md:mt-10 md:mr-10 md:text-right"} />
<main className="mb-8 md:col-span-4 md:order-1 lg:col-span-6 xl:col-span-8">
<Purchases purchases={purchases} />
<AddPurchase email={session?.user?.email} />
<AddPurchase />
</main>
</div>
)
Expand Down
6 changes: 1 addition & 5 deletions components/AddPurchase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import { useRouter } from "next/navigation";
import { useRef } from 'react';
import dayjs from 'dayjs';

interface AddPurchaseProps {
email: string | null | undefined
}

export default function AddPurchase({ email }: AddPurchaseProps) {
export default function AddPurchase() {

const router = useRouter();
const ref = useRef<HTMLFormElement>(null);
Expand All @@ -27,7 +24,6 @@ export default function AddPurchase({ email }: AddPurchaseProps) {
cost: formData.get('cost'),
category: formData.get('category'),
date: formattedDate,
email: email
}

try {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"studio:dev": "dotenv -e .env.development.local -- npx prisma studio",
"migrate:dev": "dotenv -e .env.development.local -- npx prisma migrate dev",
"db-deploy:dev": "dotenv -e .env.development.local -- npx prisma migrate deploy"
},
Expand Down

0 comments on commit f46501c

Please sign in to comment.