diff --git a/app/api/auth/[...nextauth]/_route.ts b/app/api/auth/[...nextauth]/_route.ts index 2e2718d..b3a1f4f 100644 --- a/app/api/auth/[...nextauth]/_route.ts +++ b/app/api/auth/[...nextauth]/_route.ts @@ -1,3 +1,5 @@ +// Ensure this route is accessible at /api/auth/[...nextauth] and both GET and POST are exported for NextAuth to work properly. +// If you see 405 errors, check your deployment and NEXTAUTH_URL configuration. import NextAuth from "next-auth" import { authOptions } from "@/lib/auth" diff --git a/components/main-nav.tsx b/components/main-nav.tsx index b5cdb52..2226ef1 100644 --- a/components/main-nav.tsx +++ b/components/main-nav.tsx @@ -9,6 +9,7 @@ import { siteConfig } from "@/config/site" import { cn } from "@/lib/utils" import { Icons } from "@/components/icons" import { MobileNav } from "@/components/mobile-nav" +import { ModeToggle } from "@/components/mode-toggle" interface MainNavProps { items?: MainNavItem[] @@ -20,7 +21,7 @@ export function MainNav({ items, children }: MainNavProps) { const [showMobileMenu, setShowMobileMenu] = React.useState(false) return ( -
+
@@ -46,6 +47,10 @@ export function MainNav({ items, children }: MainNavProps) { ))} ) : null} + {/* Theme toggle button for desktop */} +
+ +
+ {/* Theme toggle button for mobile, next to menu button */} +
+ +
{showMobileMenu && items && ( {children} )} diff --git a/components/user-auth-form.tsx b/components/user-auth-form.tsx index af745b3..95e75d8 100644 --- a/components/user-auth-form.tsx +++ b/components/user-auth-form.tsx @@ -34,20 +34,37 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) { async function onSubmit(data: FormData) { setIsLoading(true) - const signInResult = await signIn("email", { - email: data.email.toLowerCase(), - redirect: false, - callbackUrl: searchParams?.get("from") || "/dashboard", - }) + let signInResult: any = null; + try { + signInResult = await signIn("email", { + email: data.email.toLowerCase(), + redirect: false, + callbackUrl: searchParams?.get("from") || "/dashboard", + }); + } catch (err) { + setIsLoading(false); + return toast({ + title: "Something went wrong.", + description: "Could not reach the authentication server. Please try again later.", + variant: "destructive", + }); + } setIsLoading(false) - if (!signInResult?.ok) { + // Handle empty or invalid response + if (!signInResult || signInResult.error || !signInResult.ok) { + let description = "Your sign in request failed. Please try again."; + if (signInResult && signInResult.error === "Callback") { + description = "Authentication server returned an error. Please check your configuration or try again later."; + } else if (signInResult && signInResult.status === 405) { + description = "Authentication method not allowed. Please contact support or try again later."; + } return toast({ title: "Something went wrong.", - description: "Your sign in request failed. Please try again.", + description, variant: "destructive", - }) + }); } return toast({ diff --git a/env.mjs b/env.mjs index b3e960a..42a846b 100644 --- a/env.mjs +++ b/env.mjs @@ -1,3 +1,6 @@ +// IMPORTANT: Set NEXTAUTH_URL to your local or production domain to avoid 405 errors and authentication issues. +// For local dev: NEXTAUTH_URL=http://localhost:3000 +// For prod: NEXTAUTH_URL=https://yourdomain.com import { createEnv } from "@t3-oss/env-nextjs" import { z } from "zod"