refactor: 🛂 Refactor account switching to ask for instance
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 54s
Deploy to GitHub Pages / build (push) Failing after 1m45s
Deploy to GitHub Pages / deploy (push) Has been skipped
Docker / build (push) Failing after 17s
Mirror to Codeberg / Mirror (push) Failing after 1s

This commit is contained in:
Jesse Wierzbinski 2025-02-09 20:14:27 +01:00
parent 7e9ccbc932
commit 2e67e7858f
No known key found for this signature in database
9 changed files with 71 additions and 104 deletions

View file

@ -21,7 +21,7 @@
<UserPlus />
{{ m.sunny_pink_hyena_walk() }}
</Button>
<Button variant="secondary" size="lg" @click="signOut()" v-if="identity">
<Button variant="secondary" size="lg" @click="signOut(appData, identity)" v-if="identity">
<LogOut />
{{ m.sharp_big_mallard_reap() }}
</Button>
@ -47,7 +47,9 @@
identity.account.display_name
}}</span>
<span class="truncate text-xs">@{{
identity.account.acct
identity.account.username
}}@{{
identity.instance.domain
}}</span>
</div>
</Button>
@ -64,7 +66,7 @@
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem @click="signOut()" v-if="identity">
<DropdownMenuItem @click="signOut(appData, identity)" v-if="identity">
<LogOut />
{{ m.sharp_big_mallard_reap() }}
</DropdownMenuItem>
@ -98,48 +100,7 @@ import {
const appData = useAppData();
const isMobile = useMediaQuery("(max-width: 768px)");
const signInAction = () => signIn(appData, new URL(useBaseUrl().value));
const signOut = async (userId?: string) => {
const id = toast.loading("Signing out...");
if (!(appData.value && identity.value)) {
toast.dismiss(id);
toast.error("No app or identity data to sign out");
return;
}
const identityToRevoke = userId
? identities.value.find((i) => i.account.id === userId)
: identity.value;
if (!identityToRevoke) {
toast.dismiss(id);
toast.error("No identity to revoke");
return;
}
// Don't do anything on error, as Versia Server doesn't implement the revoke endpoint yet
await client.value
?.revokeToken(
appData.value.client_id,
identityToRevoke.tokens.access_token,
identityToRevoke.tokens.access_token,
)
.catch(() => {
// Do nothing
});
if (!userId) {
identity.value = null;
await navigateTo("/");
return;
}
identities.value = identities.value.filter((i) => i.id !== userId);
toast.dismiss(id);
toast.success("Signed out");
};
const signInAction = async () => signIn(appData, await askForInstance());
const switchAccount = async (userId: string) => {
if (userId === identity.value?.account.id) {

View file

@ -12,7 +12,7 @@
<div class="grid flex-1 text-left text-sm leading-tight">
<span class="truncate font-semibold">{{ instance?.title ?? m.short_zippy_felix_kick()
}}</span>
<span class="truncate text-xs">{{ m.top_active_ocelot_cure() }}</span>
<span class="truncate text-xs">{{ instance?.description ?? m.top_active_ocelot_cure() }}</span>
</div>
<!-- <ChevronsUpDown class="ml-auto" /> -->
</SidebarMenuButton>