Skip to content

Commit

Permalink
final commit ig
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanush-2313 committed Sep 22, 2024
1 parent d34bc8c commit 18c266b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 59 deletions.
9 changes: 4 additions & 5 deletions apps/merchant-app/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import NextAuth from "next-auth"
import { authOptions } from "../../../../lib/auth"
import NextAuth from "next-auth";
import { authOptions } from "../../../../lib/auth";

//@ts-ignore
const handler = NextAuth(authOptions)
const handler = NextAuth(authOptions);

export { handler as GET, handler as POST }
export { handler as GET, handler as POST };
66 changes: 33 additions & 33 deletions apps/merchant-app/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ import db from "@repo/db/client";
import { NextAuthOptions } from "next-auth";

export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID || "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET || ""
})
],
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
console.log("hi signin");
if (!user || !user.email) {
return false;
}
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;
}
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID || "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
}),
],
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
console.log("hi signin");
if (!user || !user.email) {
return false;
}
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",
},
update: {
name: user.name,
auth_type: account?.provider === "google" ? "Google" : "Github",
},
});
return true;
},
secret: process.env.NEXTAUTH_SECRET || "secret"
};
},
secret: process.env.NEXTAUTH_SECRET || "secret",
};
21 changes: 11 additions & 10 deletions apps/user-app/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// user-app/middleware.ts
import { NextRequest, NextResponse } from 'next/server';
import { getToken } from 'next-auth/jwt';
import { NextRequest, NextResponse } from "next/server";
import { getToken } from "next-auth/jwt";

export async function middleware(req: NextRequest) {
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET || "secret" });

const token = await getToken({
req,
secret: process.env.NEXTAUTH_SECRET || "secret",
});

if (!token) {
console.log("No token found, redirecting to sign-in");
return NextResponse.redirect(new URL('/api/auth/signin', req.url));
return NextResponse.redirect(new URL("/api/auth/signin", req.url));
}

if (req.nextUrl.pathname === '/') {
if (req.nextUrl.pathname === "/") {
console.log("Authenticated, redirecting to /transfer");
return NextResponse.redirect(new URL('/transfer', req.url));
return NextResponse.redirect(new URL("/transfer", req.url));
}

return NextResponse.next();
}

export const config = {
matcher: ['/', '/dashboard', '/transfer', '/transactions', '/p2p'], // Add other routes as needed
};
matcher: ["/", "/dashboard", "/transfer", "/transactions", "/p2p"],
};
10 changes: 0 additions & 10 deletions docker/Dockerfile.db

This file was deleted.

1 change: 0 additions & 1 deletion packages/ui/src/Appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ interface AppbarProps {
user?: {
name?: string | null;
},
// TODO: can u figure out what the type should be here?
onSignin: any,
onSignout: any
}
Expand Down

0 comments on commit 18c266b

Please sign in to comment.