From c5bc2e147073007cf743e31d7fbdcc00e0492280 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 3 Jul 2026 20:55:31 +0200 Subject: [PATCH] fix: sign-out redirect and Google OAuth user creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - signOut() cleared the cookie but never navigated, leaving the user stuck on the current page — redirect to /login on success. - better-auth's core "image" field had no matching Drizzle column (schema uses avatarUrl), so every OAuth signup threw BetterAuthError: unable_to_create_user, silently failing before a session was ever created. Remap via user.fields.image. --- apps/web/components/layout/nav.tsx | 16 ++++++++++++++-- apps/web/lib/auth/server.ts | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/web/components/layout/nav.tsx b/apps/web/components/layout/nav.tsx index 6cd195e..4813032 100644 --- a/apps/web/components/layout/nav.tsx +++ b/apps/web/components/layout/nav.tsx @@ -1,7 +1,7 @@ "use client"; import Link from "next/link"; -import { usePathname } from "next/navigation"; +import { usePathname, useRouter } from "next/navigation"; import { BookOpen, Calendar, Package, ChefHat, User, Rss, FolderOpen, ShoppingCart, Shield, Search, Compass, Menu } from "lucide-react"; import { cn } from "@/lib/utils"; import { Button, buttonVariants } from "@/components/ui/button"; @@ -36,6 +36,7 @@ const NAV_ITEMS = [ export function Nav() { const pathname = usePathname(); + const router = useRouter(); const { data: session } = authClient.useSession(); const isAdmin = (session?.user as { role?: string } | undefined)?.role === "admin"; const t = useTranslations("nav"); @@ -124,7 +125,18 @@ export function Nav() { )} - authClient.signOut()}> + { + void authClient.signOut({ + fetchOptions: { + onSuccess: () => { + router.push("/login"); + router.refresh(); + }, + }, + }); + }} + > {t("signOut")} diff --git a/apps/web/lib/auth/server.ts b/apps/web/lib/auth/server.ts index 07e0dfa..b7d1e54 100644 --- a/apps/web/lib/auth/server.ts +++ b/apps/web/lib/auth/server.ts @@ -100,6 +100,9 @@ export const auth = betterAuth({ }, user: { + fields: { + image: "avatarUrl", + }, additionalFields: { role: { type: "string",