first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
75
apps/web/modules/saas/auth/lib/server.ts
Normal file
75
apps/web/modules/saas/auth/lib/server.ts
Normal 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;
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue