better-auth/apps/web/modules/saas/auth/lib/server.ts

76 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-10-29 13:43:43 +05:00
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;
}
});