mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 03:29:16 +01:00
feat: ✨ Properly show an error when accessing authenticated routes while signed out
This commit is contained in:
parent
fc888aa530
commit
b7d22fa905
3 changed files with 64 additions and 36 deletions
|
|
@ -28,7 +28,7 @@
|
|||
}}</span>
|
||||
</div>
|
||||
</Button>
|
||||
<DropdownMenuItem @click="signIn()">
|
||||
<DropdownMenuItem @click="signInAction">
|
||||
<UserPlus />
|
||||
Add account
|
||||
</DropdownMenuItem>
|
||||
|
|
@ -78,40 +78,7 @@ import { SidebarMenuButton } from "../ui/sidebar";
|
|||
|
||||
const appData = useAppData();
|
||||
|
||||
const signIn = async () => {
|
||||
const id = toast.loading("Signing in...");
|
||||
|
||||
const output = await client.value.createApp("Versia", {
|
||||
scopes: ["read", "write", "follow", "push"],
|
||||
redirect_uris: new URL("/", useRequestURL().origin).toString(),
|
||||
website: useBaseUrl().value,
|
||||
});
|
||||
|
||||
if (!output?.data) {
|
||||
toast.dismiss(id);
|
||||
toast.error("Failed to create app");
|
||||
return;
|
||||
}
|
||||
|
||||
appData.value = output.data;
|
||||
|
||||
const url = await client.value.generateAuthUrl(
|
||||
output.data.client_id,
|
||||
output.data.client_secret,
|
||||
{
|
||||
scopes: ["read", "write", "follow", "push"],
|
||||
redirect_uri: new URL("/", useRequestURL().origin).toString(),
|
||||
},
|
||||
);
|
||||
|
||||
if (!url) {
|
||||
toast.dismiss(id);
|
||||
toast.error("Failed to generate auth URL");
|
||||
return;
|
||||
}
|
||||
|
||||
window.location.href = url;
|
||||
};
|
||||
const signInAction = () => signIn(appData);
|
||||
|
||||
const signOut = async (userId?: string) => {
|
||||
const id = toast.loading("Signing out...");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue