aau-auth-kit-ui
Version:
Plug & play shadcn/ui components for aau-auth-kit with Next.js integration
25 lines (21 loc) • 828 B
text/typescript
import { useContext, useEffect, useState } from "react";
import { AuthUIContext } from "../lib/auth-ui-provider";
export function useNoOrganization(createOrganizationUrl?: string) {
const { replace, authClient, pathname } = useContext(AuthUIContext);
const currentPathname = pathname?.();
const { data, isPending: isOrganizationLoading } =
authClient.useListOrganizations();
useEffect(() => {
console.log({ data, isOrganizationLoading, currentPathname });
if (data?.length || isOrganizationLoading || !currentPathname) return;
replace(
`${createOrganizationUrl ?? "/create-org"}?redirectTo=${window.location.href.replace(window.location.origin, "")}`
);
}, [
isOrganizationLoading,
data,
createOrganizationUrl,
replace,
currentPathname,
]);
}