fix: sign-out redirect and Google OAuth user creation

- 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.
This commit is contained in:
Arnaud
2026-07-03 20:55:31 +02:00
parent 9412529120
commit c5bc2e1470
2 changed files with 17 additions and 2 deletions
+14 -2
View File
@@ -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() {
</>
)}
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => authClient.signOut()}>
<DropdownMenuItem
onClick={() => {
void authClient.signOut({
fetchOptions: {
onSuccess: () => {
router.push("/login");
router.refresh();
},
},
});
}}
>
{t("signOut")}
</DropdownMenuItem>
</DropdownMenuContent>
+3
View File
@@ -100,6 +100,9 @@ export const auth = betterAuth({
},
user: {
fields: {
image: "avatarUrl",
},
additionalFields: {
role: {
type: "string",