mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 03:29:16 +01:00
feat: ✨ Add support for accounts on other instances
This commit is contained in:
parent
18eee4d481
commit
29b4cb43ca
13 changed files with 179 additions and 40 deletions
|
|
@ -44,7 +44,7 @@ export const useCacheRefresh = (client: MaybeRef<Client | null>) => {
|
|||
|
||||
// Get all permissions and deduplicate
|
||||
const permissions = roles
|
||||
.flatMap((r) => r.permissions)
|
||||
?.flatMap((r) => r.permissions)
|
||||
.filter((p, i, arr) => arr.indexOf(p) === i);
|
||||
|
||||
if (identity.value) {
|
||||
|
|
|
|||
|
|
@ -2,23 +2,26 @@ import { Client, type Token } from "@versia/client";
|
|||
import { toast } from "vue-sonner";
|
||||
|
||||
export const useClient = (
|
||||
origin?: MaybeRef<URL>,
|
||||
customToken: MaybeRef<Token | null> = null,
|
||||
): Ref<Client> => {
|
||||
return computed(
|
||||
() =>
|
||||
new Client(
|
||||
new URL(useBaseUrl().value),
|
||||
toValue(customToken)?.access_token ??
|
||||
identity.value?.tokens.access_token ??
|
||||
undefined,
|
||||
(error) => {
|
||||
toast.error(
|
||||
error.response.data.error ??
|
||||
"No error message provided",
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
const apiHost = window.location.origin;
|
||||
const domain = identity.value?.instance.domain;
|
||||
|
||||
return ref(
|
||||
new Client(
|
||||
toValue(origin) ??
|
||||
(domain ? new URL(`https://${domain}`) : new URL(apiHost)),
|
||||
toValue(customToken)?.access_token ??
|
||||
identity.value?.tokens.access_token ??
|
||||
undefined,
|
||||
(error) => {
|
||||
toast.error(
|
||||
error.response.data.error ?? "No error message provided",
|
||||
);
|
||||
},
|
||||
),
|
||||
) as Ref<Client>;
|
||||
};
|
||||
|
||||
export const client = useClient();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue