-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: unlink alby account * chore: address unlink account feedback
- Loading branch information
Showing
9 changed files
with
199 additions
and
14 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
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
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,20 +1,31 @@ | ||
import React from "react"; | ||
import { useLocation } from "react-router-dom"; | ||
import AuthCodeForm from "src/components/AuthCodeForm"; | ||
|
||
import Loading from "src/components/Loading"; | ||
import { useInfo } from "src/hooks/useInfo"; | ||
|
||
export default function AlbyAuthRedirect() { | ||
const { data: info } = useInfo(); | ||
const location = useLocation(); | ||
const queryParams = new URLSearchParams(location.search); | ||
const forceLogin = !!queryParams.get("force_login"); | ||
const url = info?.albyAuthUrl | ||
? `${info.albyAuthUrl}${forceLogin ? "&force_login=true" : ""}` | ||
: undefined; | ||
|
||
React.useEffect(() => { | ||
if (!info) { | ||
if (!info || !url) { | ||
return; | ||
} | ||
if (info.oauthRedirect) { | ||
window.location.href = info.albyAuthUrl; | ||
window.location.href = url; | ||
} | ||
}, [info]); | ||
}, [info, url]); | ||
|
||
return !info || info.oauthRedirect ? <Loading /> : <AuthCodeForm />; | ||
return !info || info.oauthRedirect || !url ? ( | ||
<Loading /> | ||
) : ( | ||
<AuthCodeForm url={url} /> | ||
); | ||
} |
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,87 @@ | ||
import { ExitIcon } from "@radix-ui/react-icons"; | ||
import { ExternalLinkIcon } from "lucide-react"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
import ExternalLink from "src/components/ExternalLink"; | ||
import SettingsHeader from "src/components/SettingsHeader"; | ||
import { | ||
Card, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "src/components/ui/card"; | ||
import { useToast } from "src/components/ui/use-toast"; | ||
import { useCSRF } from "src/hooks/useCSRF"; | ||
import { request } from "src/utils/request"; | ||
|
||
export function AlbyAccount() { | ||
const { data: csrf } = useCSRF(); | ||
const { toast } = useToast(); | ||
const navigate = useNavigate(); | ||
|
||
const unlink = async () => { | ||
if ( | ||
!confirm( | ||
"Are you sure you want to change the Alby Account for your hub? Your Alby Account will be disconnected from your hub and you'll need to login with a new Alby Account to access your hub." | ||
) | ||
) { | ||
return; | ||
} | ||
|
||
try { | ||
if (!csrf) { | ||
throw new Error("No CSRF token"); | ||
} | ||
await request("/api/alby/unlink-account", { | ||
method: "POST", | ||
headers: { | ||
"X-CSRF-Token": csrf, | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
navigate("/alby/auth?force_login=true"); | ||
toast({ | ||
title: "Alby Account Unlinked", | ||
description: "Please login with another Alby Account", | ||
}); | ||
} catch (error) { | ||
toast({ | ||
title: "Unlink account failed", | ||
description: (error as Error).message, | ||
variant: "destructive", | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<SettingsHeader | ||
title="Alby Account" | ||
description="Manage your Alby Account" | ||
/> | ||
<ExternalLink | ||
to="https://getalby.com/settings" | ||
className="w-full flex flex-row items-center gap-2" | ||
> | ||
<Card className="w-full"> | ||
<CardHeader> | ||
<CardTitle>Your Alby Account</CardTitle> | ||
<CardDescription className="flex gap-2 items-center"> | ||
<ExternalLinkIcon className="w-4 h-4" /> Manage your Alby Account | ||
Settings | ||
</CardDescription> | ||
</CardHeader> | ||
</Card> | ||
</ExternalLink> | ||
<Card className="w-full cursor-pointer" onClick={unlink}> | ||
<CardHeader> | ||
<CardTitle>Change Alby Account</CardTitle> | ||
<CardDescription className="flex gap-2 items-center"> | ||
<ExitIcon className="w-4 h-4" /> Link your Hub to a different Alby | ||
Account | ||
</CardDescription> | ||
</CardHeader> | ||
</Card> | ||
</> | ||
); | ||
} |
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