fix(auth): migrate from next-auth to better-auth (#1453)

This commit is contained in:
dancer 2026-03-13 23:18:01 +00:00 committed by GitHub
parent 453f5bb3e6
commit b4f595a68c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 668 additions and 390 deletions

View file

@ -3,8 +3,6 @@
import { ChevronUp } from "lucide-react";
import Image from "next/image";
import { useRouter } from "next/navigation";
import type { User } from "next-auth";
import { signOut, useSession } from "next-auth/react";
import { useTheme } from "next-themes";
import {
DropdownMenu,
@ -18,23 +16,27 @@ import {
SidebarMenuButton,
SidebarMenuItem,
} from "@/components/ui/sidebar";
import { guestRegex } from "@/lib/constants";
import { signOut, useSession } from "@/lib/client";
import { LoaderIcon } from "./icons";
import { toast } from "./toast";
export function SidebarUserNav({ user }: { user: User }) {
export function SidebarUserNav({
user,
}: {
user: { email?: string | null; isAnonymous?: boolean | null };
}) {
const router = useRouter();
const { data, status } = useSession();
const { data, isPending } = useSession();
const { setTheme, resolvedTheme } = useTheme();
const isGuest = guestRegex.test(data?.user?.email ?? "");
const isGuest = data?.user?.isAnonymous ?? user.isAnonymous ?? false;
return (
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger asChild>
{status === "loading" ? (
{isPending ? (
<SidebarMenuButton className="h-10 justify-between bg-background data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground">
<div className="flex flex-row gap-2">
<div className="size-6 animate-pulse rounded-full bg-zinc-500/30" />
@ -84,7 +86,7 @@ export function SidebarUserNav({ user }: { user: User }) {
<button
className="w-full cursor-pointer"
onClick={() => {
if (status === "loading") {
if (isPending) {
toast({
type: "error",
description:
@ -98,7 +100,12 @@ export function SidebarUserNav({ user }: { user: User }) {
router.push("/login");
} else {
signOut({
redirectTo: "/",
fetchOptions: {
onSuccess: () => {
router.push("/");
router.refresh();
},
},
});
}
}}