feat: Initial user switching mutations

This commit is contained in:
2025-09-15 12:34:59 -04:00
parent c53fb152d4
commit 98876f23b8
8 changed files with 277 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
export const useUserSwitching = () => {
const session = useUserSession();
const isSwitched = computed(() => Boolean(session.data.value?.switchedBy));
const switchTo = async (userId: string | number) => {
const response = await $fetch("/api/switch-to", {
method: "POST",
body: { userId },
});
if (response.success) {
await session.fetch();
return response;
}
throw new Error(response.message || "Switch failed");
};
const switchBack = async () => {
const response = await $fetch("/api/switch-back", {
method: "POST",
});
if (response.success) {
await session.fetch();
return response;
}
throw new Error(response.message || "Switch back failed");
};
return {
isSwitched,
switchTo,
switchBack,
};
};