first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
60
apps/web/modules/saas/auth/lib/api.ts
Normal file
60
apps/web/modules/saas/auth/lib/api.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { authClient } from "@repo/auth/client";
|
||||
import { config } from "@repo/config";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
export const sessionQueryKey = ["user", "session"] as const;
|
||||
|
||||
export const useSessionQuery = () => {
|
||||
return useQuery({
|
||||
queryKey: sessionQueryKey,
|
||||
queryFn: async () => {
|
||||
const { data, error } = await authClient.getSession({
|
||||
query: {
|
||||
disableCookieCache: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message || "Failed to fetch session");
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
staleTime: Number.POSITIVE_INFINITY,
|
||||
refetchOnWindowFocus: false,
|
||||
retry: false,
|
||||
enabled: config.ui.saas.enabled,
|
||||
});
|
||||
};
|
||||
|
||||
export const userAccountQueryKey = ["user", "accounts"] as const;
|
||||
export const useUserAccountsQuery = () => {
|
||||
return useQuery({
|
||||
queryKey: userAccountQueryKey,
|
||||
queryFn: async () => {
|
||||
const { data, error } = await authClient.listAccounts();
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const userPasskeyQueryKey = ["user", "passkeys"] as const;
|
||||
export const useUserPasskeysQuery = () => {
|
||||
return useQuery({
|
||||
queryKey: userPasskeyQueryKey,
|
||||
queryFn: async () => {
|
||||
const { data, error } = await authClient.passkey.listUserPasskeys();
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue