mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 08:28:20 +01:00
27 lines
844 B
TypeScript
27 lines
844 B
TypeScript
import { LysandClient, type Token } from "@lysand-org/client";
|
|
|
|
export const useClient = (
|
|
customToken: MaybeRef<Token | null> = null,
|
|
): Ref<LysandClient> => {
|
|
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",
|
|
});
|
|
},
|
|
),
|
|
);
|
|
};
|
|
|
|
export const client = useClient();
|