-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consume sign out auth api and fix cookie token not showing in the application tab of the browser
- Loading branch information
1 parent
86bb5ca
commit 84b6981
Showing
11 changed files
with
102 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Loader2, LucideProps } from "lucide-react"; | ||
|
||
interface IconButtonProps { | ||
icon: React.ForwardRefExoticComponent< | ||
Omit<LucideProps, "ref"> & React.RefAttributes<SVGSVGElement> | ||
>; | ||
size?: number; | ||
onClick: () => void; | ||
disabled?: boolean; | ||
loading?: boolean; | ||
} | ||
|
||
const IconButton = ({ | ||
icon: Icon, | ||
size = 22, | ||
onClick, | ||
disabled, | ||
loading, | ||
}: IconButtonProps) => { | ||
return ( | ||
<button | ||
className="w-10 h-10 rounded-full flex-center transition-colors bg-accent/40 | ||
hover:bg-accent hover:drop-shadow-accent-glow disabled:pointer-events-none | ||
disabled:bg-accent/50 disabled:text-foreground/50" | ||
disabled={disabled || loading} | ||
onClick={onClick} | ||
> | ||
{loading ? <Loader2 size={size} /> : <Icon size={size} />} | ||
</button> | ||
); | ||
}; | ||
|
||
export default IconButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const SIGNUPKEY = "sign-up"; | ||
export const SIGNINKEY = "sign-in"; | ||
export const SIGNOUTKEY = "sign-out"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
client/src/pages/root/_components/header/sign-out-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { DoorOpen } from "lucide-react"; | ||
import { toast } from "sonner"; | ||
|
||
import { AuthService } from "@/lib/services/auth-service"; | ||
import IconButton from "@/components/icon-button"; | ||
import { AppRoutes } from "@/constants/routes"; | ||
import { SIGNOUTKEY } from "@/constants/keys"; | ||
|
||
const SignOutButton = () => { | ||
const navigate = useNavigate(); | ||
|
||
const { mutate, isPending } = useMutation({ | ||
mutationKey: [SIGNOUTKEY], | ||
mutationFn: AuthService.signOut, | ||
onSuccess: () => { | ||
toast.success("Signed out successfully"); | ||
navigate(AppRoutes.SignIn); | ||
}, | ||
onError: ({ message }) => toast.error(message || "Unable to sign out"), | ||
}); | ||
|
||
return <IconButton onClick={mutate} icon={DoorOpen} loading={isPending} />; | ||
}; | ||
|
||
export { SignOutButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters