Basic disabling of TFA
All checks were successful
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Successful in 1m40s
All checks were successful
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Successful in 1m40s
This commit is contained in:
parent
41b7420ec6
commit
505e62aa61
@ -95,7 +95,7 @@ const OrganizationSelector = (): ReactElement => {
|
|||||||
<ChevronsUpDownIcon className="ml-2 w-4 h-4 shrink-0 opacity-50" />
|
<ChevronsUpDownIcon className="ml-2 w-4 h-4 shrink-0 opacity-50" />
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="p-0 w-52">
|
<PopoverContent className="w-56 p-0">
|
||||||
<Command>
|
<Command>
|
||||||
<CommandInput placeholder="Search organization..." />
|
<CommandInput placeholder="Search organization..." />
|
||||||
<CommandList>
|
<CommandList>
|
||||||
|
@ -33,7 +33,7 @@ const TierSetting = (): ReactElement => {
|
|||||||
{capitalizeWords(user?.tier)}
|
{capitalizeWords(user?.tier)}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<Link href="/#pricing">
|
<Link href="/#pricing" draggable={false}>
|
||||||
<Button
|
<Button
|
||||||
className="bg-background/30"
|
className="bg-background/30"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
@ -39,11 +39,28 @@ const TFASetting = (): ReactElement => {
|
|||||||
const user: User | undefined = useUserContext(
|
const user: User | undefined = useUserContext(
|
||||||
(state: UserState) => state.user
|
(state: UserState) => state.user
|
||||||
);
|
);
|
||||||
|
const router: AppRouterInstance = useRouter();
|
||||||
|
|
||||||
const [tfaResponse, setTfaResponse] = useState<
|
const [tfaResponse, setTfaResponse] = useState<
|
||||||
UserSetupTfaResponse | undefined
|
UserSetupTfaResponse | undefined
|
||||||
>(undefined);
|
>(undefined);
|
||||||
const [enabledTfa, setEnabledTfa] = useState<boolean>(false);
|
const [enabledTfa, setEnabledTfa] = useState<boolean>(false);
|
||||||
const router: AppRouterInstance = useRouter();
|
const [disabling, setDisabling] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const onDialogStateChange = async (open: boolean) => {
|
||||||
|
if (open) {
|
||||||
|
await setupTfa();
|
||||||
|
} else if (enabledTfa) {
|
||||||
|
toast("Two-Factor Auth", {
|
||||||
|
icon: "🎉",
|
||||||
|
description:
|
||||||
|
"Successfully enabled two-factor auth on your account!",
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start setting up two-factor auth.
|
* Start setting up two-factor auth.
|
||||||
@ -57,6 +74,25 @@ const TFASetting = (): ReactElement => {
|
|||||||
setTfaResponse(data);
|
setTfaResponse(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable two-factor auth.
|
||||||
|
*/
|
||||||
|
const disableTfa = async () => {
|
||||||
|
setDisabling(true);
|
||||||
|
await apiRequest<void>({
|
||||||
|
endpoint: "/user/disable-tfa",
|
||||||
|
method: "POST",
|
||||||
|
session,
|
||||||
|
});
|
||||||
|
toast("Two-Factor Auth", {
|
||||||
|
icon: "🔓",
|
||||||
|
description: "Two-factor auth has been disabled for your account.",
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, 1500);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-5 flex items-center">
|
<div className="px-5 flex items-center">
|
||||||
{/* Name & Description */}
|
{/* Name & Description */}
|
||||||
@ -71,24 +107,16 @@ const TFASetting = (): ReactElement => {
|
|||||||
|
|
||||||
{/* Setting */}
|
{/* Setting */}
|
||||||
{hasFlag(user as User, UserFlag.TFA_ENABLED) ? (
|
{hasFlag(user as User, UserFlag.TFA_ENABLED) ? (
|
||||||
<Button size="sm" variant="destructive">
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="destructive"
|
||||||
|
onClick={disableTfa}
|
||||||
|
disabled={disabling}
|
||||||
|
>
|
||||||
Disable
|
Disable
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<Dialog
|
<Dialog onOpenChange={onDialogStateChange}>
|
||||||
onOpenChange={async (open: boolean) => {
|
|
||||||
if (open) {
|
|
||||||
setupTfa();
|
|
||||||
} else if (enabledTfa) {
|
|
||||||
toast("Two-Factor Auth", {
|
|
||||||
icon: "🎉",
|
|
||||||
description:
|
|
||||||
"Successfully enabled two-factor auth on your account!",
|
|
||||||
});
|
|
||||||
router.push("/dashboard");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<DialogTrigger>
|
<DialogTrigger>
|
||||||
<Button
|
<Button
|
||||||
className="bg-background/30"
|
className="bg-background/30"
|
||||||
|
@ -36,7 +36,7 @@ const UserSettingsHeader = ({ title }: { title: string }): ReactElement => {
|
|||||||
<Breadcrumb>
|
<Breadcrumb>
|
||||||
<BreadcrumbList>
|
<BreadcrumbList>
|
||||||
<BreadcrumbItem>
|
<BreadcrumbItem>
|
||||||
<BreadcrumbLink href="/dashboard">
|
<BreadcrumbLink href="/dashboard" draggable={false}>
|
||||||
Dashboard
|
Dashboard
|
||||||
</BreadcrumbLink>
|
</BreadcrumbLink>
|
||||||
</BreadcrumbItem>
|
</BreadcrumbItem>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user