diff --git a/apps/merchant-app/app/api/user/route.ts b/apps/merchant-app/app/api/user/route.ts new file mode 100644 index 00000000..56e9f407 --- /dev/null +++ b/apps/merchant-app/app/api/user/route.ts @@ -0,0 +1,16 @@ +import { NextResponse } from "next/server" +import prisma from "@repo/db/client"; + +export const GET = async () => { + await prisma.user.create({ + data: { + email: "asd", + name: "adsads", + number:"123123", + password:"mypass" + } + }) + return NextResponse.json({ + message: "hi there" + }) +} \ No newline at end of file diff --git a/apps/merchant-app/app/page.tsx b/apps/merchant-app/app/page.tsx index f72d01d4..16fef4f3 100644 --- a/apps/merchant-app/app/page.tsx +++ b/apps/merchant-app/app/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useBalance } from "@repo/store/balance"; +import {useBalance} from "@repo/store/balance"; export default function() { const balance = useBalance(); diff --git a/apps/merchant-app/lib/auth.ts b/apps/merchant-app/lib/auth.ts index 8d38ac07..a1c3d280 100644 --- a/apps/merchant-app/lib/auth.ts +++ b/apps/merchant-app/lib/auth.ts @@ -1,48 +1,46 @@ import GoogleProvider from "next-auth/providers/google"; import db from "@repo/db/client"; +import { AuthOptions, User, Account, Profile } from "next-auth"; -export const authOptions = { - providers: [ - GoogleProvider({ - clientId: process.env.GOOGLE_CLIENT_ID || "", - clientSecret: process.env.GOOGLE_CLIENT_SECRET || "" - }) - ], - callbacks: { - async signIn({ user, account }: { - user: { - email: string; - name: string +export const authOptions: AuthOptions = { + providers: [ + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID || "", + clientSecret: process.env.GOOGLE_CLIENT_SECRET || "" + }) + ], + callbacks: { + async signIn({ user, account }: { + user: User; + account: Account | null; + profile?: Profile; + }) { + console.log("hi signin"); + + if (!user || !user.email || !account) { + return false; + } + + await db.merchant.upsert({ + select: { + id: true }, - account: { - provider: "google" | "github" - } - }) { - console.log("hi signin") - if (!user || !user.email) { - return false; + where: { + email: user.email + }, + create: { + email: user.email, + name: user.name ?? "Unknown", + auth_type: account.provider === "google" ? "Google" : "Github" + }, + update: { + name: user.name ?? "Unknown", + auth_type: account.provider === "google" ? "Google" : "Github" } + }); - await db.merchant.upsert({ - select: { - id: true - }, - where: { - email: user.email - }, - create: { - email: user.email, - name: user.name, - auth_type: account.provider === "google" ? "Google" : "Github" // Use a prisma type here - }, - update: { - name: user.name, - auth_type: account.provider === "google" ? "Google" : "Github" // Use a prisma type here - } - }); - - return true; - } - }, - secret: process.env.NEXTAUTH_SECRET || "secret" - } \ No newline at end of file + return true; + } + }, + secret: process.env.NEXTAUTH_SECRET || "secret" +}; diff --git a/apps/user-app/app/(dashboard)/transfer/page.tsx b/apps/user-app/app/(dashboard)/transfer/page.tsx index bbfda380..0df41b0b 100644 --- a/apps/user-app/app/(dashboard)/transfer/page.tsx +++ b/apps/user-app/app/(dashboard)/transfer/page.tsx @@ -7,9 +7,12 @@ import { authOptions } from "../../lib/auth"; async function getBalance() { const session = await getServerSession(authOptions); + + const userId = Number((session?.user as { id: string }).id); + const balance = await prisma.balance.findFirst({ where: { - userId: Number(session?.user?.id) + userId: userId } }); return { @@ -19,10 +22,12 @@ async function getBalance() { } async function getOnRampTransactions() { - const session = await getServerSession(authOptions); + + const session = await getServerSession(authOptions); const userId = Number((session?.user as { id: string }).id); + const txns = await prisma.onRampTransaction.findMany({ where: { - userId: Number(session?.user?.id) + userId: userId } }); return txns.map(t => ({ diff --git a/apps/user-app/app/api/user/route.ts b/apps/user-app/app/api/user/route.ts index c6fb73a4..4883f12a 100644 --- a/apps/user-app/app/api/user/route.ts +++ b/apps/user-app/app/api/user/route.ts @@ -4,7 +4,7 @@ import { authOptions } from "../../lib/auth"; export const GET = async () => { const session = await getServerSession(authOptions); - if (session.user) { + if (session && session.user) { return NextResponse.json({ user: session.user }) diff --git a/apps/user-app/app/lib/auth.ts b/apps/user-app/app/lib/auth.ts index 56d82dd7..b265de02 100644 --- a/apps/user-app/app/lib/auth.ts +++ b/apps/user-app/app/lib/auth.ts @@ -1,8 +1,9 @@ import db from "@repo/db/client"; import CredentialsProvider from "next-auth/providers/credentials" import bcrypt from "bcrypt"; +import { AuthOptions, User } from "next-auth"; -export const authOptions = { +export const authOptions: AuthOptions = { providers: [ CredentialsProvider({ name: 'Credentials', @@ -25,9 +26,9 @@ export const authOptions = { if (passwordValidation) { return { id: existingUser.id.toString(), - name: existingUser.name, - email: existingUser.number - } + name: existingUser.name ?? "User", + email: String(existingUser.number || ""), + } satisfies User } return null; } diff --git a/docker/Dockerfile.user b/docker/Dockerfile.user index d8cde5b1..83a8cb12 100644 --- a/docker/Dockerfile.user +++ b/docker/Dockerfile.user @@ -7,12 +7,11 @@ COPY package.json package-lock.json turbo.json tsconfig.json ./ COPY apps ./apps COPY packages ./packages -# Install dependencies RUN npm install -# Can you add a script to the global package.json that does this? RUN npm run db:generate -# Can you filter the build down to just one app? -RUN npm run build +RUN cd apps/user-app && npx next build -CMD ["npm", "run", "start-user-app"] \ No newline at end of file +WORKDIR /usr/src/app/apps/user-app + +CMD ["npx", "next", "start"] diff --git a/package.json b/package.json index 85307f8a..e4f05e9d 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,15 @@ "dev": "turbo dev", "lint": "turbo lint", "format": "prettier --write \"**/*.{ts,tsx,md}\"", +<<<<<<< HEAD "db:generate": "cd packages/db && npx prisma generate && cd ../..", "start-user-app": "cd ./apps/user-app && npm run start" +======= + "db:generate":"cd packages/db && npx prisma generate && cd ../..", + "start-user-app":"cd ./apps/user-app && npx next start" + + +>>>>>>> de111df (Add dockerfile) }, "devDependencies": { "@repo/eslint-config": "*", diff --git a/packages/store/package.json b/packages/store/package.json index c652f651..249056de 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -7,5 +7,6 @@ }, "exports": { "./balance": "./src/hooks/useBalance.ts" + } }