feat: prisma, postgresql, and upgrade to auth.js@beta

This commit is contained in:
trafficlunar 2025-03-29 21:55:04 +00:00
parent 54fee71491
commit 7b799405dc
12 changed files with 720 additions and 147 deletions

View file

@ -1,21 +1,3 @@
import NextAuth from "next-auth";
import Discord from "next-auth/providers/discord";
import Github from "next-auth/providers/github";
import { handlers } from "@/lib/auth";
const handler = NextAuth({
pages: {
signIn: "/login",
},
providers: [
Discord({
clientId: process.env.DISCORD_ID!,
clientSecret: process.env.DISCORD_SECRET!,
}),
Github({
clientId: process.env.GITHUB_ID!,
clientSecret: process.env.GITHUB_SECRET!,
}),
],
});
export { handler as GET, handler as POST };
export const { GET, POST } = handlers;

View file

@ -1,13 +1,14 @@
import Link from "next/link";
import { getServerSession } from "next-auth";
import { Icon } from "@iconify/react";
import { auth } from "@/lib/auth";
import SearchBar from "./search-bar";
import ProfileOverview from "./profile-overview";
import LogoutButton from "./logout-button";
export default async function Header() {
const session = await getServerSession();
const session = await auth();
return (
<div className="sticky top-0 z-50 w-full p-4 grid grid-cols-3 gap-2 gap-x-4 items-center bg-amber-50 border-b-4 border-amber-200 shadow-md max-lg:grid-cols-2 max-sm:grid-cols-1">

View file

@ -1,7 +1,7 @@
import { getServerSession } from "next-auth";
import { auth } from "@/lib/auth";
export default async function ProfileOverview() {
const session = await getServerSession();
const session = await auth();
return (
<li title="Your profile">

View file

@ -1,10 +1,10 @@
import { getServerSession } from "next-auth";
import LoginButtons from "../components/login-buttons";
import { redirect } from "next/navigation";
import { auth } from "@/lib/auth";
import LoginButtons from "../components/login-buttons";
export default async function LoginPage() {
const session = await getServerSession();
const session = await auth();
// If the user is already logged in, redirect
if (session) {

14
src/lib/auth.ts Normal file
View file

@ -0,0 +1,14 @@
import NextAuth from "next-auth";
import Discord from "next-auth/providers/discord";
import Github from "next-auth/providers/github";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@/lib/prisma";
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [Discord, Github],
pages: {
signIn: "/login",
},
});

7
src/lib/prisma.ts Normal file
View file

@ -0,0 +1,7 @@
import { PrismaClient } from "@prisma/client";
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
export const prisma = globalForPrisma.prisma || new PrismaClient();
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;