This commit is contained in:
 Илья Шалонин 2025-10-29 13:43:43 +05:00
commit 8538ab969a
434 changed files with 44051 additions and 0 deletions

View 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;
},
});
};

View file

@ -0,0 +1,75 @@
import "server-only";
import { auth } from "@repo/auth";
import { getInvitationById } from "@repo/database";
import { headers } from "next/headers";
import { cache } from "react";
export const getSession = cache(async () => {
const session = await auth.api.getSession({
headers: await headers(),
query: {
disableCookieCache: true,
},
});
return session;
});
export const getActiveOrganization = cache(async (slug: string) => {
try {
const activeOrganization = await auth.api.getFullOrganization({
query: {
organizationSlug: slug,
},
headers: await headers(),
});
return activeOrganization;
} catch (error) {
return null;
}
});
export const getOrganizationList = cache(async () => {
try {
const organizationList = await auth.api.listOrganizations({
headers: await headers(),
});
return organizationList;
} catch (error) {
return [];
}
});
export const getUserAccounts = cache(async () => {
try {
const userAccounts = await auth.api.listUserAccounts({
headers: await headers(),
});
return userAccounts;
} catch (error) {
return [];
}
});
export const getUserPasskeys = cache(async () => {
try {
const userPasskeys = await auth.api.listPasskeys({
headers: await headers(),
});
return userPasskeys;
} catch (error) {
return [];
}
});
export const getInvitation = cache(async (id: string) => {
try {
return await getInvitationById(id);
} catch (error) {
return null;
}
});

View file

@ -0,0 +1,12 @@
import type { Session } from "@repo/auth";
import React from "react";
export const SessionContext = React.createContext<
| {
session: Session["session"] | null;
user: Session["user"] | null;
loaded: boolean;
reloadSession: () => Promise<void>;
}
| undefined
>(undefined);