Fix middleware matcher basePath issue, always show logout button
All checks were successful
Deploy to Server / deploy (push) Successful in 1m10s
All checks were successful
Deploy to Server / deploy (push) Successful in 1m10s
Next.js prepends basePath to matcher patterns, so patterns must not include /admin prefix. Logout button now always visible in sidebar. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -226,41 +226,21 @@ export function Sidebar({ locale, mobileOpen = false, onClose }: SidebarProps) {
|
||||
</div>
|
||||
</nav>
|
||||
<div className="mt-2 border-t border-accent-200/50 pt-2">
|
||||
{!mounted ? (
|
||||
<Link
|
||||
href="/login"
|
||||
onClick={onClose}
|
||||
className={`${navLinkClass} w-full text-left text-gray-700 no-underline hover:bg-accent-100/80 hover:text-gray-900 ${pathname === "/login" ? "bg-accent-200/70 font-medium text-gray-900" : ""}`}
|
||||
>
|
||||
<Icon icon="mdi:login" className="size-4" aria-hidden />
|
||||
{t("login")}
|
||||
</Link>
|
||||
) : hasStoredKey ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={async () => {
|
||||
clearSession();
|
||||
setLogoutVersion((v) => v + 1);
|
||||
onClose?.();
|
||||
await fetch("/admin/api/auth/logout", { method: "POST" });
|
||||
router.push("/login");
|
||||
router.refresh();
|
||||
}}
|
||||
className={`${navLinkClass} w-full text-left text-gray-700 hover:bg-accent-100/80 hover:text-gray-900`}
|
||||
>
|
||||
<Icon icon="mdi:logout" className="size-4" aria-hidden />
|
||||
{t("logout")}
|
||||
</button>
|
||||
) : !hasEnvKey ? (
|
||||
<Link
|
||||
href="/login"
|
||||
onClick={onClose}
|
||||
className={`${navLinkClass} w-full text-left text-gray-700 no-underline hover:bg-accent-100/80 hover:text-gray-900 ${pathname === "/login" ? "bg-accent-200/70 font-medium text-gray-900" : ""}`}
|
||||
>
|
||||
<Icon icon="mdi:login" className="size-4" aria-hidden />
|
||||
{t("login")}
|
||||
</Link>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
onClick={async () => {
|
||||
clearSession();
|
||||
setLogoutVersion((v) => v + 1);
|
||||
onClose?.();
|
||||
await fetch("/admin/api/auth/logout", { method: "POST" });
|
||||
router.push("/login");
|
||||
router.refresh();
|
||||
}}
|
||||
className={`${navLinkClass} w-full text-left text-gray-700 hover:bg-accent-100/80 hover:text-gray-900`}
|
||||
>
|
||||
<Icon icon="mdi:logout" className="size-4" aria-hidden />
|
||||
{t("logout")}
|
||||
</button>
|
||||
</div>
|
||||
<LocaleSwitcher locale={locale} />
|
||||
</aside>
|
||||
|
||||
Reference in New Issue
Block a user