Switch from SuperTokens to NextAuth.js

BREAKING CHANGE: Replace SuperTokens with NextAuth.js

Why:
- SuperTokens had persistent Traefik routing issues
- SSL certificate not issuing correctly
- Complex infrastructure (separate container)
- NextAuth runs in Next.js app (simpler, no separate service)

Changes:
- Install next-auth, @auth/prisma-adapter, prisma
- Create NextAuth API route: app/api/auth/[...nextauth]/route.ts
- Add Prisma schema for NextAuth tables (users, sessions, accounts)
- Update auth page to use NextAuth signIn()
- Remove all SuperTokens code and dependencies
- Keep same Google OAuth (just simpler integration)

Benefits:
- No separate auth service needed
- No Traefik routing issues
- Sessions stored in Montreal PostgreSQL
- Simpler configuration
- Battle-tested, widely used

All authentication data stays in Montreal!

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-17 15:12:21 -08:00
parent 8cd95607a4
commit bbb22f1c37
12 changed files with 534 additions and 632 deletions

View File

@@ -1,38 +1,22 @@
"use client";
import dynamic from "next/dynamic";
import { useEffect, useState } from "react";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
// Dynamically import SuperTokens component (client-side only)
const SuperTokensAuthComponent = dynamic(
() => import("@/app/components/SuperTokensAuthComponent"),
{ ssr: false }
);
import { useEffect } from "react";
import NextAuthComponent from "@/app/components/NextAuthComponent";
export default function AuthPage() {
const { data: session, status } = useSession();
const router = useRouter();
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
// Check if already logged in after a short delay
setTimeout(async () => {
try {
const { doesSessionExist } = await import("supertokens-web-js/recipe/session");
const exists = await doesSessionExist();
if (exists) {
router.push("/marks-account/projects");
}
} catch (error) {
// SuperTokens not initialized yet, continue to show auth page
console.log("Session check skipped");
}
}, 500);
}, [router]);
// Redirect if already authenticated
if (status === "authenticated") {
router.push("/marks-account/projects");
}
}, [status, router]);
if (!mounted) {
if (status === "loading") {
return (
<div className="flex min-h-screen items-center justify-center bg-background">
<div className="text-center">
@@ -43,6 +27,6 @@ export default function AuthPage() {
);
}
return <SuperTokensAuthComponent />;
return <NextAuthComponent />;
}