diff --git a/app/(customer)/dashboard/[slug]/projects/[projectId]/page.tsx b/app/(customer)/dashboard/[slug]/projects/[projectId]/page.tsx index e257dfef..5ae595f3 100644 --- a/app/(customer)/dashboard/[slug]/projects/[projectId]/page.tsx +++ b/app/(customer)/dashboard/[slug]/projects/[projectId]/page.tsx @@ -7,23 +7,22 @@ import { ButtonDeleteProject } from "@/components/wrappers/dashboard/projects/Bu import { CardsWithPagination } from "@/components/wrappers/common/cards-with-pagination"; import { ProjectDatabaseCard } from "@/components/wrappers/dashboard/projects/ProjectCard/ProjectDatabaseCard"; import { notFound } from "next/navigation"; -import { getCurrentOrganizationSlug } from "@/features/dashboard/organization-cookie"; import { db } from "@/db"; import { eq } from "drizzle-orm"; import { organization as drizzleOrganization } from "@/db/schema"; +import {getOrganization} from "@/lib/auth/auth"; export default async function RoutePage(props: PageParams<{ slug: string; projectId: string }>) { const { slug: organizationSlug, projectId } = await props.params; - const currentOrganizationSlug = await getCurrentOrganizationSlug(); + const organization = await getOrganization({organizationSlug}); - if (currentOrganizationSlug !== organizationSlug) { + if (!organization || organization?.slug !== organizationSlug) { notFound(); } - const org = await db.query.organization.findFirst({ - where: eq(drizzleOrganization.slug, currentOrganizationSlug), + where: eq(drizzleOrganization.slug, organization.slug), }); if (!org) notFound(); @@ -42,7 +41,7 @@ export default async function RoutePage(props: PageParams<{ slug: string; projec
{proj.name} - + diff --git a/app/(customer)/dashboard/[slug]/projects/new/page.tsx b/app/(customer)/dashboard/[slug]/projects/new/page.tsx index b610c568..56eeb310 100644 --- a/app/(customer)/dashboard/[slug]/projects/new/page.tsx +++ b/app/(customer)/dashboard/[slug]/projects/new/page.tsx @@ -1,36 +1,36 @@ -import { PageParams } from "@/types/next"; -import { Page, PageContent, PageHeader, PageTitle } from "@/features/layout/page"; -import { ProjectForm } from "@/components/wrappers/dashboard/projects/ProjectsForm/ProjectForm"; -import { notFound } from "next/navigation"; -import { getCurrentOrganizationSlug } from "@/features/dashboard/organization-cookie"; - -import { db } from "@/db"; -import { DatabaseWith, organization as drizzleOrganization } from "@/db/schema"; -import { eq } from "drizzle-orm"; +import {PageParams} from "@/types/next"; +import {Page, PageContent, PageHeader, PageTitle} from "@/features/layout/page"; +import {ProjectForm} from "@/components/wrappers/dashboard/projects/ProjectsForm/ProjectForm"; +import {notFound} from "next/navigation"; +import {db} from "@/db"; +import {DatabaseWith, organization as drizzleOrganization} from "@/db/schema"; +import {eq} from "drizzle-orm"; +import {getOrganization} from "@/lib/auth/auth"; export default async function RoutePage(props: PageParams<{ slug: string }>) { - const { slug: organizationSlug } = await props.params; + const {slug: organizationSlug} = await props.params; - const currentOrganizationSlug = await getCurrentOrganizationSlug(); - if (currentOrganizationSlug !== organizationSlug) { + const organization = await getOrganization({organizationSlug}); + + if (!organization || organization?.slug !== organizationSlug) { notFound(); } const availableDatabases = ( await db.query.database.findMany({ - where: (db, { isNull }) => isNull(db.projectId), + where: (db, {isNull}) => isNull(db.projectId), with: { agent: true, project: true, backups: true, restorations: true, }, - orderBy: (db, { desc }) => [desc(db.createdAt)], + orderBy: (db, {desc}) => [desc(db.createdAt)], }) ).filter((db) => db.project !== null) as DatabaseWith[]; const org = await db.query.organization.findFirst({ - where: eq(drizzleOrganization.slug, currentOrganizationSlug), + where: eq(drizzleOrganization.slug, organization.slug), }); if (!org) notFound(); @@ -41,7 +41,7 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) { Create new project - + ); diff --git a/app/(customer)/dashboard/[slug]/projects/page.tsx b/app/(customer)/dashboard/[slug]/projects/page.tsx index f4b041d4..c77e850d 100644 --- a/app/(customer)/dashboard/[slug]/projects/page.tsx +++ b/app/(customer)/dashboard/[slug]/projects/page.tsx @@ -1,25 +1,29 @@ import Link from "next/link"; -import { PageParams } from "@/types/next"; -import { CardsWithPagination } from "@/components/wrappers/common/cards-with-pagination"; -import { Button } from "@/components/ui/button"; -import { Page, PageActions, PageContent, PageHeader, PageTitle } from "@/features/layout/page"; -import { ProjectCard } from "@/components/wrappers/dashboard/projects/ProjectCard/ProjectCard"; -import { db } from "@/db"; -import { notFound } from "next/navigation"; -import { getOrganization } from "@/lib/auth/auth"; +import {PageParams} from "@/types/next"; +import {CardsWithPagination} from "@/components/wrappers/common/cards-with-pagination"; +import {Button} from "@/components/ui/button"; +import {Page, PageActions, PageContent, PageHeader, PageTitle} from "@/features/layout/page"; +import {ProjectCard} from "@/components/wrappers/dashboard/projects/ProjectCard/ProjectCard"; +import {db} from "@/db"; +import {notFound} from "next/navigation"; +import {getOrganization} from "@/lib/auth/auth"; export default async function RoutePage(props: PageParams<{ slug: string }>) { - const { slug: organizationSlug } = await props.params; + const {slug: organizationSlug} = await props.params; - const organization = await getOrganization(organizationSlug); + const organization = await getOrganization({organizationSlug}); if (!organization || organization?.slug !== organizationSlug) { notFound(); } const projects = await db.query.project.findMany({ - where: (project, { eq, and, not }) => and(eq(project.organizationId, organization.id), not(eq(project.isArchived, true))), + where: (project, { + eq, + and, + not + }) => and(eq(project.organizationId, organization.id), not(eq(project.isArchived, true))), with: { databases: true, }, @@ -40,7 +44,8 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) { {projects.length > 0 ? ( - + ) : ( ) { - const {slug: organizationSlug} = await props.params - const currentOrganizationSlug = await getCurrentOrganizationSlug() - const user = await requiredCurrentUser() - if(currentOrganizationSlug != organizationSlug) { + + const {slug: organizationSlug} = await props.params; + + const organization = await getOrganization({organizationSlug}); + + if (!organization) { notFound() } - const organization = await prisma.organization.findUnique({ - where:{ - slug: currentOrganizationSlug, - }, - include:{ - users:{ - include:{ - user:{ - } - }, - where: { - user: { - id: { - not: user.id, // Exclude user with id: 1 - }, - }, - }, - } - } - }) - - const users = await prisma.user.findMany({ - where: { - deleted: {not: true}, - id: {not: user.id} - } - }) - - return( @@ -55,7 +29,7 @@ export default async function RoutePage(props: PageParams<{ - + ) diff --git a/app/(customer)/dashboard/[slug]/settings/page.tsx b/app/(customer)/dashboard/[slug]/settings/page.tsx index c9662c84..d8fab5e4 100644 --- a/app/(customer)/dashboard/[slug]/settings/page.tsx +++ b/app/(customer)/dashboard/[slug]/settings/page.tsx @@ -1,6 +1,8 @@ -import {prisma} from "@/prisma"; import {PageParams} from "@/types/next"; import {Page, PageActions, PageContent, PageDescription, PageHeader, PageTitle} from "@/features/layout/page"; +import {currentUser} from "@/lib/auth/current-user"; +import {getOrganization} from "@/lib/auth/auth"; +import {notFound} from "next/navigation"; import {requiredCurrentUser} from "@/auth/current-user"; import {SettingsTabs} from "@/components/wrappers/dashboard/settings/SettingsTabs/SettingsTabs"; import {getCurrentOrganizationSlug} from "@/features/dashboard/organization-cookie"; @@ -8,45 +10,52 @@ import { DeleteOrganizationButton } from "@/components/wrappers/dashboard/organization/DeleteOrganization/DeleteOrganizationButton"; import {EditButtonSettings} from "@/components/wrappers/dashboard/settings/EditButtonSettings/EditButtonSettings"; -import {notFound} from "next/navigation"; -export default async function RoutePage(props: PageParams<{}>) { - const user = await requiredCurrentUser() +export default async function RoutePage(props: PageParams<{ slug: string }>) { + const {slug: organizationSlug} = await props.params; - const currentOrganizationSlug = await getCurrentOrganizationSlug() + const user = await currentUser(); - const organization = await prisma.organization.findUnique({ - where: { - slug: currentOrganizationSlug, - }, - include: { - users:{ - include:{ - user: {} - } - } - } - }) + const organization = await getOrganization({organizationSlug}); - const currentOrganizationUser = await prisma.userOrganization.findFirst({ - where:{ - userId: user.id, - organization:{ - slug: currentOrganizationSlug != "" ? currentOrganizationSlug : "default", - } - } - }) - if (currentOrganizationUser.role != "admin") { - notFound() + if (!organization || organization?.slug !== organizationSlug) { + notFound(); } - const settings = await prisma.settings.findUnique({ - where: { - name: "system" - } - }) + + // const organization = await prisma.organization.findUnique({ + // where: { + // slug: currentOrganizationSlug, + // }, + // include: { + // users:{ + // include:{ + // user: {} + // } + // } + // } + // }) + // + // const currentOrganizationUser = await prisma.userOrganization.findFirst({ + // where:{ + // userId: user.id, + // organization:{ + // slug: currentOrganizationSlug != "" ? currentOrganizationSlug : "default", + // } + // } + // }) + // if (currentOrganizationUser.role != "admin") { + // notFound() + // } + // + // + // const settings = await prisma.settings.findUnique({ + // where: { + // name: "system" + // } + // }) return ( @@ -59,7 +68,7 @@ export default async function RoutePage(props: PageParams<{}>) { {organization.slug != "default" ? - + : null} @@ -67,7 +76,7 @@ export default async function RoutePage(props: PageParams<{}>) { Manage your organization settings. - + {/**/} ) diff --git a/app/(customer)/dashboard/layout.tsx b/app/(customer)/dashboard/layout.tsx index 080a9a09..cbaccb61 100644 --- a/app/(customer)/dashboard/layout.tsx +++ b/app/(customer)/dashboard/layout.tsx @@ -12,8 +12,6 @@ export default async function Layout({ children }: { children: React.ReactNode } if (!user) redirect("/login"); return ( - // - // <>
@@ -25,7 +23,5 @@ export default async function Layout({ children }: { children: React.ReactNode }
- //
- //
); } diff --git a/src/components/wrappers/dashboard/organization/OrganizationForm/OrganizationForm.tsx b/src/components/wrappers/dashboard/organization/OrganizationForm/OrganizationForm.tsx index a5fddc55..0d443abc 100644 --- a/src/components/wrappers/dashboard/organization/OrganizationForm/OrganizationForm.tsx +++ b/src/components/wrappers/dashboard/organization/OrganizationForm/OrganizationForm.tsx @@ -7,36 +7,36 @@ import { Form } from "@/components/ui/form"; import { Button } from "@/components/ui/button"; import { useMutation } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; -import { Organization, User } from "@prisma/client"; import { MultiSelect } from "@/components/wrappers/common/multiselect/multi-select"; import { OrganizationFormSchema, OrganizationFormType } from "@/components/wrappers/dashboard/organization/OrganizationForm/organization-form.schema"; -import { createOrganizationAction, updateOrganizationAction } from "@/components/wrappers/dashboard/organization/organization.action"; +import { updateOrganizationAction } from "@/components/wrappers/dashboard/organization/organization.action"; import { toast } from "sonner"; +import {Member, Organization} from "better-auth/plugins"; export type organizationFormProps = { defaultValues?: Organization; - users: User[]; + members: Member[]; }; export const OrganizationForm = (props: organizationFormProps) => { const router = useRouter(); const isCreate = !Boolean(props.defaultValues); - const formatUsersList = (users: User[]) => { - return users.map((user) => ({ - value: user.id, - label: `${user.name} | ${user.email}`, + const formatUsersList = (members: Member[]) => { + return members.map((member) => ({ + value: member.id, + label: `${member.user.name} | ${member.user.email}`, })); }; - const formatDefaultUsers = (users: OrganizationFormType["users"]): string[] => { - console.log(users); - return users.map((user) => user.userId); + const formatDefaultUsers = (members: OrganizationFormType["members"]): string[] => { + console.log(members); + return members.map((member) => member.userId); }; const formattedDefaultValues = { ...props.defaultValues, - users: !isCreate ? formatDefaultUsers(props.defaultValues?.users) : [], + users: !isCreate ? formatDefaultUsers(props.defaultValues?.members) : [], }; const form = useZodForm({ @@ -47,15 +47,15 @@ export const OrganizationForm = (props: organizationFormProps) => { const mutation = useMutation({ mutationFn: async (values: OrganizationFormType) => { console.log(values); - const organization = await updateOrganizationAction({ data: values, organizationId: props.defaultValues.id }); - console.log(organization); - if (organization.data.success) { - toast.success(organization.data.actionSuccess.message); - router.push(`/dashboard/${organization.data.value.slug}/settings`); - router.refresh(); - } else { - toast.success(organization.data.actionError.message); - } + // const organization = await updateOrganizationAction({ data: values, organizationId: props.defaultValues.id }); + // console.log(organization); + // if (organization.data.success) { + // // toast.success(organization.data.actionSuccess.message); + // // router.push(`/dashboard/${organization.data.value.slug}/settings`); + // // router.refresh(); + // } else { + // // toast.success(organization.data.actionError.message); + // } }, }); @@ -113,7 +113,7 @@ export const OrganizationForm = (props: organizationFormProps) => { Databases { - const {currentUser, users} = props; + // const {currentUser, users} = props; return (
@@ -21,12 +19,12 @@ export const SettingsUsersTab = (props: SettingsUsersTabProps) => {

List of organization's users

- + {/**/}
) @@ -35,63 +33,65 @@ export const SettingsUsersTab = (props: SettingsUsersTabProps) => { export type usersDataTableProps = { - currentUser: User; - table: any, + // currentUser: User; + // table: any, } -export const UsersDataTable = ({currentUser, table}: usersDataTableProps) => { +export const UsersDataTable = ( + // {currentUser, table}: usersDataTableProps +) => { return (
- - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => { - return ( - - {header.isPlaceholder - ? null - : flexRender( - header.column.columnDef.header, - header.getContext() - )} - - ) - })} - - ))} - - - {table.getRowModel().rows?.length ? ( - table.getRowModel().rows.map((row: Row) => { - return( - - {row.getVisibleCells().map((cell) => ( - - {flexRender( - cell.column.columnDef.cell, - cell.getContext(), - )} - - ))} - - ) - } + {/*
*/} + {/* */} + {/* {table.getHeaderGroups().map((headerGroup) => (*/} + {/* */} + {/* {headerGroup.headers.map((header) => {*/} + {/* return (*/} + {/* */} + {/* {header.isPlaceholder*/} + {/* ? null*/} + {/* : flexRender(*/} + {/* header.column.columnDef.header,*/} + {/* header.getContext()*/} + {/* )}*/} + {/* */} + {/* )*/} + {/* })}*/} + {/* */} + {/* ))}*/} + {/* */} + {/* */} + {/* {table.getRowModel().rows?.length ? (*/} + {/* table.getRowModel().rows.map((row: Row) => {*/} + {/* return(*/} + {/* */} + {/* {row.getVisibleCells().map((cell) => (*/} + {/* */} + {/* {flexRender(*/} + {/* cell.column.columnDef.cell,*/} + {/* cell.getContext(),*/} + {/* )}*/} + {/* */} + {/* ))}*/} + {/* */} + {/* )*/} + {/* }*/} - )) : ( - - - No results. - - - )} - -
+ {/* )) : (*/} + {/* */} + {/* */} + {/* No results.*/} + {/* */} + {/* */} + {/* )}*/} + {/* */} + {/**/}
) } diff --git a/src/components/wrappers/dashboard/sideBar/app-sidebar.tsx b/src/components/wrappers/dashboard/sideBar/app-sidebar.tsx index 8935b10d..609892a7 100644 --- a/src/components/wrappers/dashboard/sideBar/app-sidebar.tsx +++ b/src/components/wrappers/dashboard/sideBar/app-sidebar.tsx @@ -9,17 +9,19 @@ import { SidebarMenu as SM, SidebarMenuItem, } from "@/components/ui/sidebar"; -import { SidebarItem, SidebarMenu } from "@/components/wrappers/dashboard/sideBar/SideBarMenu/SideBarMenu"; -import { OrganizationCombobox } from "@/components/wrappers/dashboard/organization/organization-combobox"; -import { SideBarLogo } from "@/components/wrappers/dashboard/sideBar/SideBarLogo/SideBarLogo"; -import { SideBarFooterCredit } from "@/components/wrappers/dashboard/sideBar/SideBarFooterCredit/SideBarFooterCredit"; -import { LoggedInButton } from "@/components/wrappers/dashboard/loggedInButton/LoggedInButton"; -import { Layers, ChartArea, Settings, ShieldHalf } from "lucide-react"; -import { authClient } from "@/lib/auth/auth-client"; -import { SidebarContentA } from "./sidebar-content"; +import {SidebarItem, SidebarMenu} from "@/components/wrappers/dashboard/sideBar/SideBarMenu/SideBarMenu"; +import {OrganizationCombobox} from "@/components/wrappers/dashboard/organization/organization-combobox"; +import {SideBarLogo} from "@/components/wrappers/dashboard/sideBar/SideBarLogo/SideBarLogo"; +import {SideBarFooterCredit} from "@/components/wrappers/dashboard/sideBar/SideBarFooterCredit/SideBarFooterCredit"; +import {LoggedInButton} from "@/components/wrappers/dashboard/loggedInButton/LoggedInButton"; +import {Layers, ChartArea, Settings, ShieldHalf} from "lucide-react"; +import {authClient} from "@/lib/auth/auth-client"; +import {SidebarContentA} from "./sidebar-content"; +import {getActiveMember, getOrganization} from "@/lib/auth/auth"; +import {notFound} from "next/navigation"; export async function AppSidebar() { - /*const member = await getActiveMember(); + const member = await getActiveMember(); console.log("member", member); @@ -27,31 +29,33 @@ export async function AppSidebar() { return notFound(); } - const organization = await getOrganization(member.organizationId); + const organization = await getOrganization({organizationId: member.organizationId}); //todo: à revoir - console.log("memebrer", member); - console.log("aoaoaoaoaoa", organization);*/ + console.log("membrer", member); + console.log("aoaoaoaoaoa", organization); return ( - + - + - + + + - + - + ); diff --git a/src/components/wrappers/dashboard/sideBar/sidebar-content.tsx b/src/components/wrappers/dashboard/sideBar/sidebar-content.tsx index 28fd2b71..f9157d8b 100644 --- a/src/components/wrappers/dashboard/sideBar/sidebar-content.tsx +++ b/src/components/wrappers/dashboard/sideBar/sidebar-content.tsx @@ -7,10 +7,9 @@ import { SidebarItem, SidebarMenu } from "./SideBarMenu/SideBarMenu"; export const SidebarContentA = () => { const { data: activeOrganization } = authClient.useActiveOrganization(); const { data: organizations } = authClient.useListOrganizations(); - const { data: session } = useSession(); + const member = authClient.useActiveMember(); // Moved here — always called - console.log("sesssssion", session); const appItems: SidebarItem[] = [ { @@ -31,19 +30,15 @@ export const SidebarContentA = () => { }, ]; - if (activeOrganization) { - const member = authClient.useActiveMember(); - - if (member && member.data && (member.data.role === "admin" || member.data.role === "owner")) { - appItems.push({ - type: "list", - content: { - title: "Settings", - url: "settings", - icon: , - }, - }); - } + if (activeOrganization && member?.data?.role === "admin" || member?.data?.role === "owner") { + appItems.push({ + type: "list", + content: { + title: "Settings", + url: "settings", + icon: , + }, + }); } const adminItems: SidebarItem[] = [ @@ -67,22 +62,13 @@ export const SidebarContentA = () => { return ( activeOrganization && ( - + Application - {/*(user.role === "superadmin" || user.role === "admin") && ( - - Administration - - - - - )*/} - ) ); }; diff --git a/src/env.mjs b/src/env.mjs index 421e7fe6..f18f15fd 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -5,10 +5,6 @@ import packageJson from "../package.json" with { type: "json" }; const { version } = packageJson; export const env = createEnv({ - /* - * Serverside Environment variables, not available on the client. - * Will throw if you access these variables on the client. - */ server: { NODE_ENV: z.enum(["development", "production"]).optional(), DATABASE_URL: z.string().url().optional(), @@ -36,23 +32,12 @@ export const env = createEnv({ STORAGE_TYPE: z.string().optional(), }, - /* - * Environment variables available on the client (and server). - * - * 💡 You'll get type errors if these are not prefixed with NEXT_PUBLIC_. - */ client: { NEXT_PUBLIC_PROJECT_NAME: z.string().optional(), NEXT_PUBLIC_PROJECT_DESCRIPTION: z.string().optional(), NEXT_PUBLIC_PROJECT_URL: z.string(), NEXT_PUBLIC_PROJECT_VERSION: z.string(), }, - /* - * Due to how Next.js bundles environment variables on Edge and Client, - * we need to manually destructure them to make sure all are included in bundle. - * - * 💡 You'll get type errors if not all variables from `server` & `client` are included here. - */ runtimeEnv: { NEXT_PUBLIC_PROJECT_NAME: process.env.NEXT_PUBLIC_PROJECT_NAME, NEXT_PUBLIC_PROJECT_DESCRIPTION: process.env.NEXT_PUBLIC_PROJECT_DESCRIPTION, diff --git a/src/lib/auth/auth.ts b/src/lib/auth/auth.ts index 31893303..8de7e950 100644 --- a/src/lib/auth/auth.ts +++ b/src/lib/auth/auth.ts @@ -1,13 +1,13 @@ -import { betterAuth } from "better-auth"; -import { drizzleAdapter } from "better-auth/adapters/drizzle"; -import { db } from "@/db"; -import { env } from "@/env.mjs"; -import { nextCookies } from "better-auth/next-js"; -import { admin as adminPlugin, openAPI, organization } from "better-auth/plugins"; -import { ac, admin, user, pending, superadmin, orgOwner, orgAdmin, orgMember } from "@/lib/auth/permissions"; +import {betterAuth} from "better-auth"; +import {drizzleAdapter} from "better-auth/adapters/drizzle"; +import {db} from "@/db"; +import {env} from "@/env.mjs"; +import {nextCookies} from "better-auth/next-js"; +import {admin as adminPlugin, openAPI, organization} from "better-auth/plugins"; +import {ac, admin, orgAdmin, orgMember, orgOwner, pending, superadmin, user} from "@/lib/auth/permissions"; -import { headers } from "next/headers"; -import { count, eq } from "drizzle-orm"; +import {headers} from "next/headers"; +import {count, eq} from "drizzle-orm"; import * as drizzleUser from "@/db/schema/01_user"; import * as drizzleOrganization from "@/db/schema/02_organization"; @@ -140,7 +140,7 @@ export const signInUser = async (email: string, password: string) => { };*/ export const createUser = async (name: string, email: string, password: string, role: "user" | "pending" | "admin" | "superadmin" = "pending") => { - const user = await auth.api.createUser({ + return await auth.api.createUser({ headers: await headers(), body: { name, @@ -149,24 +149,18 @@ export const createUser = async (name: string, email: string, password: string, role, }, }); - - return user; }; export const getSessions = async () => { - const sessions = await auth.api.listSessions({ + return await auth.api.listSessions({ headers: await headers(), }); - - return sessions; }; export const getSession = async () => { - const session = await auth.api.getSession({ + return await auth.api.getSession({ headers: await headers(), }); - - return session; }; export const revokeSession = async (e: string) => { @@ -182,11 +176,9 @@ export const revokeSession = async (e: string) => { }; export const getAccounts = async () => { - const sessions = await auth.api.listUserAccounts({ + return await auth.api.listUserAccounts({ headers: await headers(), }); - - return sessions; }; export const unlinkAccount = async (provider: string, account: string) => { @@ -203,26 +195,35 @@ export const unlinkAccount = async (provider: string, account: string) => { } catch (e) {} }; -export const getOrganization = async (organizationSlug?: string) => { - try { - const organization = await auth.api.getFullOrganization({ - headers: await headers(), - query: { - organizationSlug, - }, - }); +export const getOrganization = async ({ + organizationId, + organizationSlug, + }: { + organizationId?: string; + organizationSlug?: string; +}) => { + const query = organizationId + ? { organizationId } + : { organizationSlug }; - return organization; - } catch (e) {} + console.log(query); + + try { + return await auth.api.getFullOrganization({ + headers: await headers(), + query, + }); + } catch (e) { + console.error(e); + return null; + } }; export const listOrganizations = async () => { try { - const organizations = await auth.api.listOrganizations({ + return await auth.api.listOrganizations({ headers: await headers(), }); - - return organizations; } catch (e) {} };