@schemavaults/auth-ui 0.8.11 → 0.8.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AccountCard/account_card.d.ts +8 -2
- package/dist/components/AccountCard/account_card.js +4 -9
- package/dist/components/AccountCard/account_card.js.map +1 -1
- package/dist/components/AccountCard/index.d.ts +1 -1
- package/dist/components/AccountCard/useMyOrganizations.d.ts +4 -8
- package/dist/components/AccountCard/useMyOrganizations.js +15 -26
- package/dist/components/AccountCard/useMyOrganizations.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PropsWithChildren, ReactElement, ReactNode } from "react";
|
|
2
2
|
import type { UserData } from "@schemavaults/auth-react-provider";
|
|
3
|
-
import { type
|
|
3
|
+
import { type OrganizationMembershipRoleDetails } from "@schemavaults/auth-common";
|
|
4
4
|
import { type SchemaVaultsAppEnvironment } from "@schemavaults/app-definitions";
|
|
5
5
|
export interface AccountDetailsCardProps {
|
|
6
6
|
cardClassName?: string;
|
|
@@ -12,7 +12,13 @@ export interface AccountDetailsCardProps {
|
|
|
12
12
|
isAdmin: boolean;
|
|
13
13
|
appEnvironment: SchemaVaultsAppEnvironment;
|
|
14
14
|
user: UserData | null;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Optional SSR-preloaded organization memberships for the current user.
|
|
17
|
+
* Used as SWR `fallbackData` for `useMyOrganizations` so the card renders
|
|
18
|
+
* the user's orgs on first paint instead of waiting for the client-side
|
|
19
|
+
* fetch of `/api/me/organizations`.
|
|
20
|
+
*/
|
|
21
|
+
preloaded_memberships?: readonly OrganizationMembershipRoleDetails[];
|
|
16
22
|
}
|
|
17
23
|
export declare function AccountDetailsCard(props: AccountDetailsCardProps): ReactElement;
|
|
18
24
|
export default AccountDetailsCard;
|
|
@@ -5,7 +5,7 @@ import { MAXIMUM_USER_ORGANIZATIONS, } from "@schemavaults/auth-common";
|
|
|
5
5
|
import SignOutButton from "../SignOutButton";
|
|
6
6
|
import ViewFullUserProfileButton from "./view_full_user_profile";
|
|
7
7
|
import ViewAdminDashboardButton from "./view_admin_page_link";
|
|
8
|
-
import { useMyOrganizations
|
|
8
|
+
import { useMyOrganizations } from "./useMyOrganizations";
|
|
9
9
|
import { getHardcodedClientWebAppDomain, SCHEMAVAULTS_AUTH_APP_DEFINITION, } from "@schemavaults/app-definitions";
|
|
10
10
|
import { Building2, Plus } from "lucide-react";
|
|
11
11
|
export function AccountDetailsCard(props) {
|
|
@@ -14,16 +14,11 @@ export function AccountDetailsCard(props) {
|
|
|
14
14
|
const auth_server_uri = getHardcodedClientWebAppDomain(SCHEMAVAULTS_AUTH_APP_DEFINITION.app_id, props.appEnvironment);
|
|
15
15
|
const cardClassName = cn("w-full", props.cardClassName);
|
|
16
16
|
const showLinkToAuthServerAccountPage = !props.isAuthServerAccountPage;
|
|
17
|
-
// Convert preloaded OrganizationDefinitions to MyOrganizationMembership format for SWR initialData
|
|
18
|
-
const preloadedMemberships = props.organizations?.map((org) => ({
|
|
19
|
-
organization_id: org.organization_id,
|
|
20
|
-
organization_name: org.name,
|
|
21
|
-
role: "",
|
|
22
|
-
created_at: org.created_at,
|
|
23
|
-
}));
|
|
24
17
|
const { data: memberships } = useMyOrganizations({
|
|
25
18
|
enabled: !!props.isAuthServerAccountPage,
|
|
26
|
-
initialData: props.isAuthServerAccountPage
|
|
19
|
+
initialData: props.isAuthServerAccountPage
|
|
20
|
+
? props.preloaded_memberships
|
|
21
|
+
: undefined,
|
|
27
22
|
});
|
|
28
23
|
return (_jsxs(Card, { className: cardClassName, children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: "Account Details" }), _jsx(CardDescription, { children: "View and manage your SchemaVaults account." })] }), _jsx(CardContent, { children: _jsxs("div", { className: "flex flex-col items-start justify-start gap-2", children: [_jsx(KeyValueWithSkeleton, { label: "User ID", value: currentUser?.uid }), _jsx(KeyValueWithSkeleton, { label: "Email", value: currentUser?.email }), props.isAuthServerAccountPage && (_jsxs("div", { className: "flex flex-row items-center justify-start gap-2 flex-wrap", children: [_jsx("h3", { className: "text-lg font-bold", children: "Organizations:" }), memberships && memberships.length > 0 ? (_jsx(_Fragment, { children: memberships.map((membership) => (_jsx(Link, { href: `/org/${membership.organization_id}`, children: _jsxs(Button, { variant: "outline", size: "sm", className: "flex flex-row flex-nowrap gap-2", children: [_jsx(Building2, { className: "h-4 w-4" }), membership.organization_name, membership.role && (_jsxs("span", { className: "text-xs text-muted-foreground", children: ["(", membership.role, ")"] }))] }) }, membership.organization_id))) })) : (_jsx("p", { className: "text-sm text-muted-foreground", children: "No organizations" })), (!memberships || memberships.length < MAXIMUM_USER_ORGANIZATIONS) && (_jsx(Link, { href: "/org/new", children: _jsxs(Button, { variant: "outline", size: "sm", className: "flex flex-row flex-nowrap gap-2", children: [_jsx(Plus, { className: "h-4 w-4" }), "Create Organization"] }) }))] }))] }) }), _jsx(CardFooter, { children: _jsxs("div", { className: "flex flex-row items-start justify-start flex-wrap gap-2", children: [_jsx(SignOutButton, { Link: props.Link }), showLinkToAuthServerAccountPage && (_jsx(ViewFullUserProfileButton, { navigate: async () => {
|
|
29
24
|
const accountUrl = `${auth_server_uri}/account`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account_card.js","sourceRoot":"","sources":["../../../src/components/AccountCard/account_card.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EACL,MAAM,EACN,IAAI,EACJ,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,EAAE,GACH,MAAM,kBAAkB,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"account_card.js","sourceRoot":"","sources":["../../../src/components/AccountCard/account_card.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EACL,MAAM,EACN,IAAI,EACJ,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,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,CAAC,IAAI,GAAI,EAClC,+BAA+B,IAAI,CAClC,KAAC,yBAAyB,IACxB,QAAQ,EAAE,KAAK,IAAI,EAAE;gCACnB,MAAM,UAAU,GACd,GAAG,eAAe,UAAoC,CAAC;gCACzD,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;4BACnC,CAAC,GACD,CACH,EACD,KAAC,wBAAwB,IACvB,QAAQ,EAAE,KAAK,IAAI,EAAE;gCACnB,MAAM,UAAU,GAAG,GAAG,eAAe,QAAiB,CAAC;gCACvD,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;4BACnC,CAAC,EACD,KAAK,EAAE,KAAK,CAAC,OAAO,GACpB,IACE,GACK,IACR,CACR,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { AccountDetailsCard, AccountDetailsCard as default, AccountDetailsCard as AccountCard, } from "./account_card";
|
|
2
2
|
export type * from "./account_card";
|
|
3
3
|
export { useMyOrganizations, clearMyOrganizationsCache } from "./useMyOrganizations";
|
|
4
|
-
export type {
|
|
4
|
+
export type { OrganizationMembershipRoleDetails, UseMyOrganizationsOptions, } from "./useMyOrganizations";
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { type SWRResponse, useSWRConfig } from "swr";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
organization_name: string;
|
|
5
|
-
role: string;
|
|
6
|
-
created_at: number;
|
|
7
|
-
}
|
|
2
|
+
import type { OrganizationMembershipRoleDetails } from "@schemavaults/auth-common";
|
|
3
|
+
export type { OrganizationMembershipRoleDetails } from "@schemavaults/auth-common";
|
|
8
4
|
export interface UseMyOrganizationsOptions {
|
|
9
5
|
enabled?: boolean;
|
|
10
|
-
initialData?: readonly
|
|
6
|
+
initialData?: readonly OrganizationMembershipRoleDetails[] | undefined;
|
|
11
7
|
}
|
|
12
8
|
export declare function clearMyOrganizationsCache(mutate: ReturnType<typeof useSWRConfig>["mutate"]): void;
|
|
13
|
-
export declare function useMyOrganizations({ enabled, initialData, }: UseMyOrganizationsOptions): SWRResponse<readonly
|
|
9
|
+
export declare function useMyOrganizations({ enabled, initialData, }: UseMyOrganizationsOptions): SWRResponse<readonly OrganizationMembershipRoleDetails[]>;
|
|
14
10
|
export default useMyOrganizations;
|
|
@@ -1,38 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useCallback } from "react";
|
|
2
3
|
import { useToast } from "@schemavaults/ui";
|
|
3
4
|
import useSWR from "swr";
|
|
4
|
-
|
|
5
|
+
import { useAuth, } from "@schemavaults/auth-react-provider";
|
|
6
|
+
const MY_ORGANIZATIONS_SWR_KEY = "/api/me/organizations";
|
|
5
7
|
export function clearMyOrganizationsCache(mutate) {
|
|
6
|
-
mutate((key) => key.startsWith(
|
|
8
|
+
mutate((key) => key.startsWith(MY_ORGANIZATIONS_SWR_KEY), undefined, {
|
|
7
9
|
revalidate: true,
|
|
8
10
|
});
|
|
9
11
|
}
|
|
10
12
|
export function useMyOrganizations({ enabled = true, initialData, }) {
|
|
11
13
|
const { toast } = useToast();
|
|
12
|
-
|
|
14
|
+
const auth = useAuth();
|
|
15
|
+
const clientRef = auth.ready ? auth.client : null;
|
|
16
|
+
const ready = !!(enabled && auth.ready && clientRef?.current);
|
|
17
|
+
const fetcher = useCallback(async () => {
|
|
18
|
+
const authClient = clientRef?.current ?? null;
|
|
19
|
+
if (!authClient) {
|
|
20
|
+
throw new Error("Auth client is not available to list organization memberships");
|
|
21
|
+
}
|
|
13
22
|
try {
|
|
14
|
-
|
|
15
|
-
method: "GET",
|
|
16
|
-
credentials: "include",
|
|
17
|
-
});
|
|
18
|
-
if (!response.ok || response.status !== 200) {
|
|
19
|
-
throw new Error(`Failed to list user organizations (response status: ${response.status})!`);
|
|
20
|
-
}
|
|
21
|
-
const body = await response.json();
|
|
22
|
-
if (typeof body !== "object" ||
|
|
23
|
-
!body ||
|
|
24
|
-
!("success" in body) ||
|
|
25
|
-
!body.success) {
|
|
26
|
-
throw new Error("Received failure response when attempting to list user organizations");
|
|
27
|
-
}
|
|
28
|
-
if (!("data" in body) ||
|
|
29
|
-
typeof body.data !== "object" ||
|
|
30
|
-
!body.data ||
|
|
31
|
-
!("memberships" in body.data) ||
|
|
32
|
-
!Array.isArray(body.data.memberships)) {
|
|
33
|
-
throw new Error("Failed to extract 'memberships' array from response!");
|
|
34
|
-
}
|
|
35
|
-
return body.data.memberships;
|
|
23
|
+
return await authClient.listMyOrganizationMemberships();
|
|
36
24
|
}
|
|
37
25
|
catch (error) {
|
|
38
26
|
toast({
|
|
@@ -42,7 +30,8 @@ export function useMyOrganizations({ enabled = true, initialData, }) {
|
|
|
42
30
|
});
|
|
43
31
|
throw error;
|
|
44
32
|
}
|
|
45
|
-
},
|
|
33
|
+
}, [clientRef, toast]);
|
|
34
|
+
return useSWR(ready ? MY_ORGANIZATIONS_SWR_KEY : null, fetcher, {
|
|
46
35
|
fallbackData: initialData ? [...initialData] : undefined,
|
|
47
36
|
});
|
|
48
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMyOrganizations.js","sourceRoot":"","sources":["../../../src/components/AccountCard/useMyOrganizations.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,MAA0C,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"useMyOrganizations.js","sourceRoot":"","sources":["../../../src/components/AccountCard/useMyOrganizations.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,MAA0C,MAAM,KAAK,CAAC;AAE7D,OAAO,EACL,OAAO,GAER,MAAM,mCAAmC,CAAC;AAS3C,MAAM,wBAAwB,GAAG,uBAAuB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KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,IAAI,EACvC,OAAO,EACP;QACE,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;KACzD,CACF,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/auth-ui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.19",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "React.js UI components for authentication/authorization shared between different SchemaVaults apps",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"react": "^19.2.6",
|
|
17
17
|
"react-dom": "^19.2.6",
|
|
18
18
|
"next": "^16.2.6",
|
|
19
|
-
"@schemavaults/ui": "^0.
|
|
20
|
-
"@schemavaults/auth-react-provider": "0.11.
|
|
21
|
-
"@schemavaults/app-definitions": "0.7.
|
|
22
|
-
"@schemavaults/auth-common": "0.12.
|
|
19
|
+
"@schemavaults/ui": "^0.54.3",
|
|
20
|
+
"@schemavaults/auth-react-provider": "0.11.17",
|
|
21
|
+
"@schemavaults/app-definitions": "0.7.1",
|
|
22
|
+
"@schemavaults/auth-common": "0.12.9",
|
|
23
23
|
"lucide-react": "0.575.0",
|
|
24
24
|
"swr": "2.3.4",
|
|
25
25
|
"postcss": "8.5.3",
|