diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..d65b47b --- /dev/null +++ b/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,6 @@ +import NextAuth from "next-auth"; +import { authOptions } from "@/lib/auth/authOptions"; + +const handler = NextAuth(authOptions); + +export { handler as GET, handler as POST }; diff --git a/app/api/auth/[[...path]]/route.ts b/app/api/auth/[[...path]]/route.ts deleted file mode 100644 index d8e971a..0000000 --- a/app/api/auth/[[...path]]/route.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { NextRequest, NextResponse } from "next/server"; -import SuperTokens from "supertokens-node"; -import { backendConfig } from "@/lib/supertokens/backendConfig"; -import { getAppDirRequestHandler } from "supertokens-node/nextjs"; - -// Tell Next.js this is a dynamic route (don't evaluate at build time) -export const dynamic = 'force-dynamic'; -export const runtime = 'nodejs'; - -// Initialize SuperTokens lazily (only when first request comes in) -let initialized = false; - -function ensureInitialized() { - if (!initialized && typeof window === 'undefined') { - SuperTokens.init(backendConfig()); - initialized = true; - } -} - -export async function GET(request: NextRequest) { - ensureInitialized(); - const handleRequest = getAppDirRequestHandler(NextResponse); - const response = await handleRequest(request); - return response; -} - -export async function POST(request: NextRequest) { - ensureInitialized(); - const handleRequest = getAppDirRequestHandler(NextResponse); - const response = await handleRequest(request); - return response; -} - -export async function DELETE(request: NextRequest) { - ensureInitialized(); - const handleRequest = getAppDirRequestHandler(NextResponse); - const response = await handleRequest(request); - return response; -} - -export async function PUT(request: NextRequest) { - ensureInitialized(); - const handleRequest = getAppDirRequestHandler(NextResponse); - const response = await handleRequest(request); - return response; -} - -export async function PATCH(request: NextRequest) { - ensureInitialized(); - const handleRequest = getAppDirRequestHandler(NextResponse); - const response = await handleRequest(request); - return response; -} - -export async function HEAD(request: NextRequest) { - ensureInitialized(); - const handleRequest = getAppDirRequestHandler(NextResponse); - const response = await handleRequest(request); - return response; -} diff --git a/app/auth/page.tsx b/app/auth/page.tsx index 6e40119..c7780bd 100644 --- a/app/auth/page.tsx +++ b/app/auth/page.tsx @@ -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 (