2024-06-08 01:09:15 +02:00
|
|
|
import { LysandClient, type Token } from "@lysand-org/client";
|
2024-06-10 05:24:55 +02:00
|
|
|
import { useCurrentIdentity } from "./Identities";
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-06-08 01:09:15 +02:00
|
|
|
export const useClient = (
|
2024-06-10 05:24:55 +02:00
|
|
|
customToken: MaybeRef<Token | null> = null,
|
|
|
|
|
): Ref<LysandClient> => {
|
|
|
|
|
const identity = useCurrentIdentity();
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-04-27 06:50:30 +02:00
|
|
|
return computed(
|
|
|
|
|
() =>
|
2024-06-08 01:09:15 +02:00
|
|
|
new LysandClient(
|
|
|
|
|
new URL(useBaseUrl().value),
|
2024-06-10 05:24:55 +02:00
|
|
|
toValue(customToken)?.access_token ??
|
|
|
|
|
identity.value?.tokens.access_token ??
|
|
|
|
|
undefined,
|
2024-06-08 01:09:15 +02:00
|
|
|
),
|
2024-04-27 06:50:30 +02:00
|
|
|
);
|
2024-04-22 09:38:51 +02:00
|
|
|
};
|