Add Next.js client app with Prisma and auth

Introduce a new 'client' Next.js app scaffold: configuration files (next.config.ts, eslint.config.mjs, postcss, tsconfig), Prisma config and schema, app routes including NextAuth API and server actions, session/provider utilities, proxy, public assets, README and .gitignore. Also add IDE project files under .idea and a root README to initialize the repository structure for development.
This commit is contained in:
Aryan Singh committed 2026-02-25 21:55:41 -06:00
1 parent d90ea58fc3
commit 50bc2eea74
30 files changed
+8913

No files matched your search

@@ -0,0 +1,46 @@
//setup google auth
//only allow google login and store the user in the database if they login for the first time
import NextAuth, { type NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { createUserOnFirstGoogleLogin } from "./serverActions";
const googleClientId = process.env.GOOGLE_CLIENT_ID;
const googleClientSecret = process.env.GOOGLE_CLIENT_SECRET;
if (!googleClientId || !googleClientSecret) {
throw new Error(
"Missing Google OAuth env vars. Set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET.",
);
}
export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: googleClientId,
clientSecret: googleClientSecret,
}),
],
callbacks: {
async signIn({ user, account }) {
if (account?.provider !== "google") {
return false;
}
if (!user.email) {
return false;
}
await createUserOnFirstGoogleLogin({
email: user.email,
name: user.name,
});
return true;
},
},
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
@@ -0,0 +1,28 @@
//auth functions again teh database go here and get then gen imported to the route file to be used
"use server";
import { prisma } from "@/lib/prisma";
type UpsertGoogleUserInput = {
email: string;
name?: string | null;
};
export const createUserOnFirstGoogleLogin = async ({
email,
name,
}: UpsertGoogleUserInput) => {
const existingUser = await prisma.user.findUnique({
where: { email },
select: { id: true },
});
if (!existingUser) {
await prisma.user.create({
data: {
email,
name: name ?? null,
},
});
}
};