diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..f691d9cd --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: Build on PR + +on: + pull_request: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: npm install + + - name: Run Build + run: npm run build 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..736fb8df --- /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", + password:"secret", + number:"123" + } + }) + 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..473ed22c 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..49ff49eb 100644 --- a/apps/merchant-app/lib/auth.ts +++ b/apps/merchant-app/lib/auth.ts @@ -1,5 +1,8 @@ import GoogleProvider from "next-auth/providers/google"; import db from "@repo/db/client"; +import { signIn } from "next-auth/react"; +import { Account, User } from "next-auth"; +import { AdapterUser } from "next-auth/adapters"; export const authOptions = { providers: [ @@ -9,19 +12,19 @@ export const authOptions = { }) ], callbacks: { - async signIn({ user, account }: { - user: { - email: string; - name: string - }, - account: { - provider: "google" | "github" - } - }) { + async signIn({ + user,account + }: { + user:User | AdapterUser; account : Account | null + }) + + { console.log("hi signin") if (!user || !user.email) { return false; } + if(!account) + return false; await db.merchant.upsert({ select: { @@ -32,7 +35,7 @@ export const authOptions = { }, create: { email: user.email, - name: user.name, + name: user.name ?? "", auth_type: account.provider === "google" ? "Google" : "Github" // Use a prisma type here }, update: { diff --git a/apps/user-app/app/api/user/route.ts b/apps/user-app/app/api/user/route.ts index c6fb73a4..896065f2 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?.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..e53e5dee 100644 --- a/apps/user-app/app/lib/auth.ts +++ b/apps/user-app/app/lib/auth.ts @@ -1,6 +1,8 @@ import db from "@repo/db/client"; import CredentialsProvider from "next-auth/providers/credentials" import bcrypt from "bcrypt"; +import { JWT } from "next-auth/jwt"; +import { Session } from "next-auth"; export const authOptions = { providers: [ @@ -56,10 +58,11 @@ export const authOptions = { secret: process.env.JWT_SECRET || "secret", callbacks: { // TODO: can u fix the type here? Using any is bad - async session({ token, session }: any) { - session.user.id = token.sub - - return session + async session({ token, session }: {session: Session; token: JWT}) { + if(session.user && token.sub){ + session.user.id = token.sub; + } + return session; } } } diff --git a/apps/user-app/types/next-auth.d.ts b/apps/user-app/types/next-auth.d.ts new file mode 100644 index 00000000..ba0ac34b --- /dev/null +++ b/apps/user-app/types/next-auth.d.ts @@ -0,0 +1,13 @@ +// apps/user-app/types/next-auth.d.ts +import NextAuth from "next-auth"; + +declare module "next-auth" { + interface Session { + user?: { + id?: string; + name?: string | null; + email?: string | null; + image?: string | null; + }; + } +}