enzostvs HF Staff commited on
Commit
b3c2102
·
1 Parent(s): e26e90f

logout button

Browse files
src/components/deploy-button/deploy-button.tsx CHANGED
@@ -2,11 +2,13 @@
2
  import { useState } from "react";
3
  import classNames from "classnames";
4
  import { toast } from "react-toastify";
 
5
 
6
  import SpaceIcon from "@/assets/space.svg";
7
  import Loading from "../loading/loading";
8
  import Login from "../login/login";
9
  import { Auth } from "./../../../utils/types";
 
10
 
11
  const MsgToast = ({ url }: { url: string }) => (
12
  <div className="w-full flex items-center justify-center gap-3">
@@ -31,6 +33,7 @@ function DeployButton({
31
  error: boolean;
32
  auth?: Auth;
33
  }) {
 
34
  const [open, setOpen] = useState(false);
35
  const [loading, setLoading] = useState(false);
36
  const [path, setPath] = useState<string | undefined>(undefined);
@@ -79,16 +82,29 @@ function DeployButton({
79
  return (
80
  <div className="relative flex items-center justify-end">
81
  {auth && (
82
- <p className="mr-3 text-xs lg:text-sm text-gray-300">
83
- <span className="max-lg:hidden">Connected as </span>
84
- <a
85
- href={`https://huggingface.co/${auth.preferred_username}`}
86
- target="_blank"
87
- className="underline hover:text-white"
 
 
 
88
  >
89
- {auth.preferred_username}
90
- </a>
91
- </p>
 
 
 
 
 
 
 
 
 
 
92
  )}
93
  <button
94
  className={classNames(
 
2
  import { useState } from "react";
3
  import classNames from "classnames";
4
  import { toast } from "react-toastify";
5
+ import { FaPowerOff } from "react-icons/fa6";
6
 
7
  import SpaceIcon from "@/assets/space.svg";
8
  import Loading from "../loading/loading";
9
  import Login from "../login/login";
10
  import { Auth } from "./../../../utils/types";
11
+ import { useCookie } from "react-use";
12
 
13
  const MsgToast = ({ url }: { url: string }) => (
14
  <div className="w-full flex items-center justify-center gap-3">
 
33
  error: boolean;
34
  auth?: Auth;
35
  }) {
36
+ const [, , removeToken] = useCookie("hf_token");
37
  const [open, setOpen] = useState(false);
38
  const [loading, setLoading] = useState(false);
39
  const [path, setPath] = useState<string | undefined>(undefined);
 
82
  return (
83
  <div className="relative flex items-center justify-end">
84
  {auth && (
85
+ <>
86
+ <button
87
+ className="mr-2 cursor-pointer"
88
+ onClick={() => {
89
+ if (confirm("Are you sure you want to log out?")) {
90
+ removeToken();
91
+ window.location.reload();
92
+ }
93
+ }}
94
  >
95
+ <FaPowerOff className="text-lg text-red-500" />
96
+ </button>
97
+ <p className="mr-3 text-xs lg:text-sm text-gray-300">
98
+ <span className="max-lg:hidden">Connected as </span>
99
+ <a
100
+ href={`https://huggingface.co/${auth.preferred_username}`}
101
+ target="_blank"
102
+ className="underline hover:text-white"
103
+ >
104
+ {auth.preferred_username}
105
+ </a>
106
+ </p>
107
+ </>
108
  )}
109
  <button
110
  className={classNames(