mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 16:38:20 +01:00
28 lines
903 B
TypeScript
28 lines
903 B
TypeScript
import { LysandClient, type Token } from "@lysand-org/client";
|
|
import { useCurrentIdentity } from "./Identities";
|
|
|
|
export const useClient = (
|
|
customToken: MaybeRef<Token | null> = null,
|
|
): Ref<LysandClient> => {
|
|
const identity = useCurrentIdentity();
|
|
|
|
return computed(
|
|
() =>
|
|
new LysandClient(
|
|
new URL(useBaseUrl().value),
|
|
toValue(customToken)?.access_token ??
|
|
identity.value?.tokens.access_token ??
|
|
undefined,
|
|
(error) => {
|
|
useEvent("notification:new", {
|
|
title: "An error occured",
|
|
type: "error",
|
|
description:
|
|
error.response.data.error ??
|
|
"No error message provided",
|
|
});
|
|
},
|
|
),
|
|
);
|
|
};
|