Skip to content
Closed
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
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",
number:"123123",
password:"mypass"
}
})
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
82 changes: 40 additions & 42 deletions apps/merchant-app/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -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"
}
return true;
}
},
secret: process.env.NEXTAUTH_SECRET || "secret"
};
11 changes: 8 additions & 3 deletions apps/user-app/app/(dashboard)/transfer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 => ({
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 && session.user) {
return NextResponse.json({
user: session.user
})
Expand Down
9 changes: 5 additions & 4 deletions apps/user-app/app/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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;
}
Expand Down
9 changes: 4 additions & 5 deletions docker/Dockerfile.user
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
WORKDIR /usr/src/app/apps/user-app

CMD ["npx", "next", "start"]
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
1 change: 1 addition & 0 deletions packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
},
"exports": {
"./balance": "./src/hooks/useBalance.ts"

}
}
Loading