Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions apps/merchant-app/app/api/user/route.ts
Original file line number Diff line number Diff line change
@@ -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"
})
}
2 changes: 1 addition & 1 deletion apps/merchant-app/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useBalance } from "@repo/store/balance";
import {useBalance} from "@repo/store/balance";

export default function() {
const balance = useBalance();
Expand Down
23 changes: 13 additions & 10 deletions apps/merchant-app/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -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: {
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion apps/user-app/app/api/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
11 changes: 7 additions & 4 deletions apps/user-app/app/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions apps/user-app/types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -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;
};
}
}
Loading