Skip to content

Commit

Permalink
fix(auth): fix logout button not logging out completely (#446)
Browse files Browse the repository at this point in the history
fix(auth): fix logout btn not logging out completely

chore: simplify code
  • Loading branch information
Redm4x authored Nov 8, 2024
1 parent 2923eca commit 96f45dd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
10 changes: 6 additions & 4 deletions apps/deploy-web/src/components/layout/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function AccountMenu() {
setOpen(false);
}}
>
<div className="flex items-center justify-center w-full">
<div className="flex w-full items-center justify-center">
{!isLoading && user ? (
<div className="w-full">
{username && (
Expand Down Expand Up @@ -82,19 +82,21 @@ export function AccountMenu() {
My Alerts
</CustomDropdownLinkItem>
<DropdownMenuSeparator />
<CustomDropdownLinkItem onClick={() => router.push(UrlService.logout())} icon={<LogOut />}>
<CustomDropdownLinkItem onClick={() => (window.location.href = UrlService.logout())} icon={<LogOut />}>
Logout
</CustomDropdownLinkItem>
</div>
) : (
<div className="w-full space-y-1">
<CustomDropdownLinkItem
className="bg-primary !text-white hover:bg-primary/80 hover:text-white focus:bg-primary/80 justify-center p-2"
className="justify-center bg-primary p-2 !text-white hover:bg-primary/80 hover:text-white focus:bg-primary/80"
onClick={() => router.push(UrlService.signup())}
>
Sign up
</CustomDropdownLinkItem>
<CustomDropdownLinkItem onClick={() => router.push(UrlService.login())} className="justify-center p-2">Sign in</CustomDropdownLinkItem>
<CustomDropdownLinkItem onClick={() => router.push(UrlService.login())} className="justify-center p-2">
Sign in
</CustomDropdownLinkItem>
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const MobileSidebarUser: React.FunctionComponent = () => {
}}
/>
<SidebarRouteButton
useNextLinkTag={false}
route={{
title: "Logout",
icon: props => <LogOut {...props} />,
Expand Down
57 changes: 30 additions & 27 deletions apps/deploy-web/src/components/layout/SidebarRouteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { ReactNode } from "react";
import React, { ReactNode } from "react";
import { buttonVariants } from "@akashnetwork/ui/components";
import { cn } from "@akashnetwork/ui/utils";
import Link from "next/link";
Expand All @@ -13,36 +13,39 @@ type Props = {
route: ISidebarRoute;
isNavOpen?: boolean;
className?: string;
useNextLinkTag?: boolean;
};

export const SidebarRouteButton: React.FunctionComponent<Props> = ({ route, className = "", isNavOpen = true }) => {
export const SidebarRouteButton: React.FunctionComponent<Props> = ({ route, className = "", isNavOpen = true, useNextLinkTag = true }) => {
const pathname = usePathname();
const isSelected = route.url === UrlService.home() ? pathname === "/" : route.activeRoutes.some(x => pathname?.startsWith(x));

return (
<li className={className}>
<Link
target={route.target ?? "_self"}
rel={route.rel ? route.rel : ""}
href={route.url}
className={cn(
buttonVariants({ variant: isSelected ? "secondary" : "ghost", size: "sm" }),
"flex w-full items-center justify-start text-current hover:no-underline",
{
["font-bold"]: isSelected,
["min-w-[initial] px-4 py-1"]: isNavOpen,
["w-[45px] min-w-0 p-2"]: !isNavOpen
}
)}
data-testid={route.testId}
>
{!!route.icon && (
<span className={cn("z-[100] min-w-0", { ["m-[initial]"]: isNavOpen, ["mx-auto"]: !isNavOpen })}>
{route.icon({ className: cn({ ["text-primary font-bold"]: isSelected, ["mx-auto"]: !isNavOpen }, "text-xs") })}
</span>
)}
{isNavOpen && <span className="mb-1 ml-4 mt-1 min-w-0 flex-auto whitespace-nowrap">{route.title}</span>}
</Link>
</li>
const linkProps: React.ComponentProps<typeof Link> & React.ComponentProps<"a"> & { "data-testid": string | undefined } = {
target: route.target ?? "_self",
rel: route.rel ? route.rel : "",
href: route.url,
className: cn(
buttonVariants({ variant: isSelected ? "secondary" : "ghost", size: "sm" }),
"flex w-full items-center justify-start text-current hover:no-underline",
{
["font-bold"]: isSelected,
["min-w-[initial] px-4 py-1"]: isNavOpen,
["w-[45px] min-w-0 p-2"]: !isNavOpen
}
),
"data-testid": route.testId
};

const innerContent = (
<>
{!!route.icon && (
<span className={cn("z-[100] min-w-0", { ["m-[initial]"]: isNavOpen, ["mx-auto"]: !isNavOpen })}>
{route.icon({ className: cn({ ["text-primary font-bold"]: isSelected, ["mx-auto"]: !isNavOpen }, "text-xs") })}
</span>
)}
{isNavOpen && <span className="mb-1 ml-4 mt-1 min-w-0 flex-auto whitespace-nowrap">{route.title}</span>}
</>
);

return <li className={className}>{useNextLinkTag ? <Link {...linkProps}>{innerContent}</Link> : <a {...linkProps}>{innerContent}</a>}</li>;
};

0 comments on commit 96f45dd

Please sign in to comment.