@mdxui/auth 1.1.0

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.
@@ -0,0 +1,211 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ButtonHTMLAttributes, ReactNode } from 'react';
4
+ import { useAuth } from '@workos-inc/authkit-react';
5
+
6
+ interface SignInButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
7
+ /** Button content (defaults to "Sign In") */
8
+ children?: ReactNode;
9
+ /** Custom onClick handler (in addition to signIn) */
10
+ onSignIn?: () => void;
11
+ }
12
+ /**
13
+ * Sign In Button
14
+ *
15
+ * A simple button that triggers the WorkOS AuthKit sign-in flow.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * import { SignInButton } from '@mdxui/auth'
20
+ *
21
+ * function Header() {
22
+ * return (
23
+ * <nav>
24
+ * <SignInButton />
25
+ * </nav>
26
+ * )
27
+ * }
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * // With custom styling
33
+ * <SignInButton className="bg-blue-500 text-white px-4 py-2 rounded">
34
+ * Get Started
35
+ * </SignInButton>
36
+ * ```
37
+ */
38
+ declare function SignInButton({ children, onSignIn, className, disabled, ...props }: SignInButtonProps): react_jsx_runtime.JSX.Element;
39
+
40
+ interface SignOutButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
41
+ /** Button content (defaults to "Sign Out") */
42
+ children?: ReactNode;
43
+ /** Custom onClick handler (in addition to signOut) */
44
+ onSignOut?: () => void;
45
+ }
46
+ /**
47
+ * Sign Out Button
48
+ *
49
+ * A simple button that triggers the WorkOS AuthKit sign-out flow.
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * import { SignOutButton } from '@mdxui/auth'
54
+ *
55
+ * function Header() {
56
+ * const { user } = useAuth()
57
+ *
58
+ * if (!user) return null
59
+ *
60
+ * return (
61
+ * <nav>
62
+ * <span>{user.email}</span>
63
+ * <SignOutButton />
64
+ * </nav>
65
+ * )
66
+ * }
67
+ * ```
68
+ *
69
+ * @example
70
+ * ```tsx
71
+ * // With custom styling
72
+ * <SignOutButton className="text-red-500 underline">
73
+ * Log out
74
+ * </SignOutButton>
75
+ * ```
76
+ */
77
+ declare function SignOutButton({ children, onSignOut, className, disabled, ...props }: SignOutButtonProps): react_jsx_runtime.JSX.Element;
78
+
79
+ interface UserMenuProps {
80
+ /** Custom render function for the trigger button */
81
+ renderTrigger?: (props: {
82
+ user: NonNullable<ReturnType<typeof useAuth>['user']>;
83
+ displayName: string;
84
+ initials: string;
85
+ }) => ReactNode;
86
+ /** Custom render function for the menu content */
87
+ renderMenu?: (props: {
88
+ user: NonNullable<ReturnType<typeof useAuth>['user']>;
89
+ displayName: string;
90
+ initials: string;
91
+ signOut: () => void;
92
+ }) => ReactNode;
93
+ /** Additional CSS class */
94
+ className?: string;
95
+ }
96
+ /**
97
+ * User Menu Component
98
+ *
99
+ * A customizable user menu that displays user info and provides sign-out functionality.
100
+ * This is a headless component - you provide the render functions to control the UI.
101
+ *
102
+ * For a pre-built menu with @mdxui/primitives, use the UserMenu from @mdxui/do or @mdxui/cockpit.
103
+ *
104
+ * @example
105
+ * ```tsx
106
+ * import { UserMenu } from '@mdxui/auth'
107
+ *
108
+ * function Header() {
109
+ * return (
110
+ * <UserMenu
111
+ * renderTrigger={({ user, initials }) => (
112
+ * <button className="flex items-center gap-2">
113
+ * <div className="w-8 h-8 rounded-full bg-gray-200 flex items-center justify-center">
114
+ * {user.profilePictureUrl ? (
115
+ * <img src={user.profilePictureUrl} alt="" className="rounded-full" />
116
+ * ) : (
117
+ * initials
118
+ * )}
119
+ * </div>
120
+ * <span>{user.firstName}</span>
121
+ * </button>
122
+ * )}
123
+ * renderMenu={({ user, signOut }) => (
124
+ * <div className="dropdown-menu">
125
+ * <div className="p-2">
126
+ * <p>{user.email}</p>
127
+ * </div>
128
+ * <button onClick={signOut}>Sign Out</button>
129
+ * </div>
130
+ * )}
131
+ * />
132
+ * )
133
+ * }
134
+ * ```
135
+ *
136
+ * @example
137
+ * ```tsx
138
+ * // Simple usage with just a sign-out button
139
+ * <UserMenu
140
+ * renderTrigger={({ displayName }) => <span>{displayName}</span>}
141
+ * renderMenu={({ signOut }) => <button onClick={signOut}>Sign Out</button>}
142
+ * />
143
+ * ```
144
+ */
145
+ declare function UserMenu({ renderTrigger, renderMenu, className }: UserMenuProps): react_jsx_runtime.JSX.Element | null;
146
+
147
+ interface TeamSwitcherProps {
148
+ /**
149
+ * Render function for the wrapper when in an organization.
150
+ * The OrganizationSwitcher widget will be rendered inside this wrapper.
151
+ */
152
+ renderWrapper?: (children: ReactNode) => ReactNode;
153
+ /**
154
+ * Render function for when there is no organization.
155
+ * If not provided, returns null.
156
+ */
157
+ renderNoOrganization?: () => ReactNode;
158
+ /** CSS class name for the organization switcher wrapper */
159
+ className?: string;
160
+ }
161
+ /**
162
+ * TeamSwitcher component that uses WorkOS authentication.
163
+ *
164
+ * Shows the WorkOS OrganizationSwitcher widget when authenticated with an organization,
165
+ * or a custom "no organization" component when not.
166
+ *
167
+ * This is a headless component - you provide render functions for the UI.
168
+ * For a pre-built sidebar menu version, use your design system's sidebar components.
169
+ *
170
+ * @example
171
+ * ```tsx
172
+ * import { TeamSwitcher } from '@mdxui/auth'
173
+ * import { SidebarMenu, SidebarMenuItem } from '@mdxui/primitives/sidebar'
174
+ * import { Building2 } from 'lucide-react'
175
+ *
176
+ * function MyTeamSwitcher() {
177
+ * return (
178
+ * <TeamSwitcher
179
+ * renderWrapper={(children) => (
180
+ * <SidebarMenu>
181
+ * <SidebarMenuItem>
182
+ * <div className="organization-switcher-wrapper">
183
+ * {children}
184
+ * </div>
185
+ * </SidebarMenuItem>
186
+ * </SidebarMenu>
187
+ * )}
188
+ * renderNoOrganization={() => (
189
+ * <SidebarMenu>
190
+ * <SidebarMenuItem>
191
+ * <div className="flex items-center gap-2">
192
+ * <Building2 className="size-4" />
193
+ * <span>No Organization</span>
194
+ * </div>
195
+ * </SidebarMenuItem>
196
+ * </SidebarMenu>
197
+ * )}
198
+ * />
199
+ * )
200
+ * }
201
+ * ```
202
+ *
203
+ * @example
204
+ * ```tsx
205
+ * // Simple usage without custom rendering
206
+ * <TeamSwitcher className="my-org-switcher" />
207
+ * ```
208
+ */
209
+ declare function TeamSwitcher({ renderWrapper, renderNoOrganization, className, }: TeamSwitcherProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
210
+
211
+ export { SignInButton, SignOutButton, TeamSwitcher, UserMenu };
@@ -0,0 +1,144 @@
1
+ // src/components/sign-in-button.tsx
2
+ import { useAuth } from "@workos-inc/authkit-react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ function SignInButton({
5
+ children = "Sign In",
6
+ onSignIn,
7
+ className,
8
+ disabled,
9
+ ...props
10
+ }) {
11
+ const { signIn, isLoading } = useAuth();
12
+ const handleClick = () => {
13
+ onSignIn?.();
14
+ signIn();
15
+ };
16
+ return /* @__PURE__ */ jsx(
17
+ "button",
18
+ {
19
+ type: "button",
20
+ onClick: handleClick,
21
+ disabled: disabled || isLoading,
22
+ className: className ?? "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-[var(--radius-md)] text-sm font-medium transition-colors bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 disabled:opacity-50 disabled:pointer-events-none",
23
+ ...props,
24
+ children
25
+ }
26
+ );
27
+ }
28
+
29
+ // src/components/sign-out-button.tsx
30
+ import { useAuth as useAuth2 } from "@workos-inc/authkit-react";
31
+ import { jsx as jsx2 } from "react/jsx-runtime";
32
+ function SignOutButton({
33
+ children = "Sign Out",
34
+ onSignOut,
35
+ className,
36
+ disabled,
37
+ ...props
38
+ }) {
39
+ const { signOut, isLoading } = useAuth2();
40
+ const handleClick = () => {
41
+ onSignOut?.();
42
+ signOut();
43
+ };
44
+ return /* @__PURE__ */ jsx2(
45
+ "button",
46
+ {
47
+ type: "button",
48
+ onClick: handleClick,
49
+ disabled: disabled || isLoading,
50
+ className: className ?? "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-[var(--radius-md)] text-sm font-medium transition-colors bg-secondary text-secondary-foreground hover:bg-secondary/80 h-10 px-4 disabled:opacity-50 disabled:pointer-events-none",
51
+ ...props,
52
+ children
53
+ }
54
+ );
55
+ }
56
+
57
+ // src/components/user-menu.tsx
58
+ import { useAuth as useAuth3 } from "@workos-inc/authkit-react";
59
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
60
+ function getInitials(name) {
61
+ if (!name) return "?";
62
+ const parts = name.trim().split(/\s+/);
63
+ if (parts.length === 1) return parts[0].charAt(0).toUpperCase();
64
+ return (parts[0].charAt(0) + parts[parts.length - 1].charAt(0)).toUpperCase();
65
+ }
66
+ function UserMenu({ renderTrigger, renderMenu, className }) {
67
+ const { user, signOut, isLoading } = useAuth3();
68
+ if (isLoading) {
69
+ return /* @__PURE__ */ jsx3("div", { className, children: /* @__PURE__ */ jsx3("div", { className: "flex items-center gap-2 p-2", children: /* @__PURE__ */ jsx3("div", { className: "h-8 w-8 animate-pulse rounded-full bg-muted" }) }) });
70
+ }
71
+ if (!user) {
72
+ return null;
73
+ }
74
+ const displayName = user.firstName ? `${user.firstName}${user.lastName ? ` ${user.lastName}` : ""}` : user.email;
75
+ const initials = getInitials(
76
+ user.firstName ? `${user.firstName} ${user.lastName ?? ""}` : user.email
77
+ );
78
+ const triggerProps = { user, displayName, initials };
79
+ const menuProps = { user, displayName, initials, signOut };
80
+ if (!renderTrigger && !renderMenu) {
81
+ return /* @__PURE__ */ jsx3("div", { className, children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 p-2", children: [
82
+ /* @__PURE__ */ jsx3("div", { className: "h-8 w-8 rounded-full bg-muted flex items-center justify-center text-sm font-medium", children: user.profilePictureUrl ? /* @__PURE__ */ jsx3(
83
+ "img",
84
+ {
85
+ src: user.profilePictureUrl,
86
+ alt: displayName,
87
+ className: "h-full w-full rounded-full object-cover"
88
+ }
89
+ ) : initials }),
90
+ /* @__PURE__ */ jsxs("div", { className: "text-sm", children: [
91
+ /* @__PURE__ */ jsx3("p", { className: "font-medium", children: displayName }),
92
+ /* @__PURE__ */ jsx3("p", { className: "text-muted-foreground text-xs", children: user.email })
93
+ ] }),
94
+ /* @__PURE__ */ jsx3(
95
+ "button",
96
+ {
97
+ type: "button",
98
+ onClick: () => signOut(),
99
+ className: "ml-auto text-sm text-muted-foreground hover:text-foreground",
100
+ children: "Sign out"
101
+ }
102
+ )
103
+ ] }) });
104
+ }
105
+ return /* @__PURE__ */ jsxs("div", { className, children: [
106
+ renderTrigger?.(triggerProps),
107
+ renderMenu?.(menuProps)
108
+ ] });
109
+ }
110
+
111
+ // src/components/team-switcher.tsx
112
+ import { useAuth as useAuth4 } from "@workos-inc/authkit-react";
113
+ import { OrganizationSwitcher } from "@workos-inc/widgets";
114
+ import { jsx as jsx4 } from "react/jsx-runtime";
115
+ function TeamSwitcher({
116
+ renderWrapper,
117
+ renderNoOrganization,
118
+ className
119
+ }) {
120
+ const { getAccessToken, switchToOrganization, organizationId } = useAuth4();
121
+ if (!organizationId) {
122
+ return renderNoOrganization?.() ?? null;
123
+ }
124
+ const handleSwitchOrganization = ({
125
+ organizationId: organizationId2
126
+ }) => {
127
+ return switchToOrganization({ organizationId: organizationId2 });
128
+ };
129
+ const widget = /* @__PURE__ */ jsx4("div", { className: `organization-switcher-wrapper ${className ?? ""}`, children: /* @__PURE__ */ jsx4(
130
+ OrganizationSwitcher,
131
+ {
132
+ authToken: getAccessToken,
133
+ switchToOrganization: handleSwitchOrganization
134
+ }
135
+ ) });
136
+ return renderWrapper ? renderWrapper(widget) : widget;
137
+ }
138
+ export {
139
+ SignInButton,
140
+ SignOutButton,
141
+ TeamSwitcher,
142
+ UserMenu
143
+ };
144
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/sign-in-button.tsx","../../src/components/sign-out-button.tsx","../../src/components/user-menu.tsx","../../src/components/team-switcher.tsx"],"sourcesContent":["'use client'\n\nimport { useAuth } from '@workos-inc/authkit-react'\nimport type { ReactNode, ButtonHTMLAttributes } from 'react'\n\nexport interface SignInButtonProps\n extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {\n /** Button content (defaults to \"Sign In\") */\n children?: ReactNode\n /** Custom onClick handler (in addition to signIn) */\n onSignIn?: () => void\n}\n\n/**\n * Sign In Button\n *\n * A simple button that triggers the WorkOS AuthKit sign-in flow.\n *\n * @example\n * ```tsx\n * import { SignInButton } from '@mdxui/auth'\n *\n * function Header() {\n * return (\n * <nav>\n * <SignInButton />\n * </nav>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom styling\n * <SignInButton className=\"bg-blue-500 text-white px-4 py-2 rounded\">\n * Get Started\n * </SignInButton>\n * ```\n */\nexport function SignInButton({\n children = 'Sign In',\n onSignIn,\n className,\n disabled,\n ...props\n}: SignInButtonProps) {\n const { signIn, isLoading } = useAuth()\n\n const handleClick = () => {\n onSignIn?.()\n signIn()\n }\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n disabled={disabled || isLoading}\n className={\n className ??\n 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-[var(--radius-md)] text-sm font-medium transition-colors bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 disabled:opacity-50 disabled:pointer-events-none'\n }\n {...props}\n >\n {children}\n </button>\n )\n}\n","'use client'\n\nimport { useAuth } from '@workos-inc/authkit-react'\nimport type { ReactNode, ButtonHTMLAttributes } from 'react'\n\nexport interface SignOutButtonProps\n extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {\n /** Button content (defaults to \"Sign Out\") */\n children?: ReactNode\n /** Custom onClick handler (in addition to signOut) */\n onSignOut?: () => void\n}\n\n/**\n * Sign Out Button\n *\n * A simple button that triggers the WorkOS AuthKit sign-out flow.\n *\n * @example\n * ```tsx\n * import { SignOutButton } from '@mdxui/auth'\n *\n * function Header() {\n * const { user } = useAuth()\n *\n * if (!user) return null\n *\n * return (\n * <nav>\n * <span>{user.email}</span>\n * <SignOutButton />\n * </nav>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom styling\n * <SignOutButton className=\"text-red-500 underline\">\n * Log out\n * </SignOutButton>\n * ```\n */\nexport function SignOutButton({\n children = 'Sign Out',\n onSignOut,\n className,\n disabled,\n ...props\n}: SignOutButtonProps) {\n const { signOut, isLoading } = useAuth()\n\n const handleClick = () => {\n onSignOut?.()\n signOut()\n }\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n disabled={disabled || isLoading}\n className={\n className ??\n 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-[var(--radius-md)] text-sm font-medium transition-colors bg-secondary text-secondary-foreground hover:bg-secondary/80 h-10 px-4 disabled:opacity-50 disabled:pointer-events-none'\n }\n {...props}\n >\n {children}\n </button>\n )\n}\n","'use client'\n\nimport { useAuth } from '@workos-inc/authkit-react'\nimport type { ReactNode } from 'react'\n\nexport interface UserMenuProps {\n /** Custom render function for the trigger button */\n renderTrigger?: (props: {\n user: NonNullable<ReturnType<typeof useAuth>['user']>\n displayName: string\n initials: string\n }) => ReactNode\n /** Custom render function for the menu content */\n renderMenu?: (props: {\n user: NonNullable<ReturnType<typeof useAuth>['user']>\n displayName: string\n initials: string\n signOut: () => void\n }) => ReactNode\n /** Additional CSS class */\n className?: string\n}\n\n/**\n * Get initials from a name (first letter of first and last name)\n */\nfunction getInitials(name: string | undefined): string {\n if (!name) return '?'\n const parts = name.trim().split(/\\s+/)\n if (parts.length === 1) return parts[0].charAt(0).toUpperCase()\n return (\n parts[0].charAt(0) + parts[parts.length - 1].charAt(0)\n ).toUpperCase()\n}\n\n/**\n * User Menu Component\n *\n * A customizable user menu that displays user info and provides sign-out functionality.\n * This is a headless component - you provide the render functions to control the UI.\n *\n * For a pre-built menu with @mdxui/primitives, use the UserMenu from @mdxui/do or @mdxui/cockpit.\n *\n * @example\n * ```tsx\n * import { UserMenu } from '@mdxui/auth'\n *\n * function Header() {\n * return (\n * <UserMenu\n * renderTrigger={({ user, initials }) => (\n * <button className=\"flex items-center gap-2\">\n * <div className=\"w-8 h-8 rounded-full bg-gray-200 flex items-center justify-center\">\n * {user.profilePictureUrl ? (\n * <img src={user.profilePictureUrl} alt=\"\" className=\"rounded-full\" />\n * ) : (\n * initials\n * )}\n * </div>\n * <span>{user.firstName}</span>\n * </button>\n * )}\n * renderMenu={({ user, signOut }) => (\n * <div className=\"dropdown-menu\">\n * <div className=\"p-2\">\n * <p>{user.email}</p>\n * </div>\n * <button onClick={signOut}>Sign Out</button>\n * </div>\n * )}\n * />\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Simple usage with just a sign-out button\n * <UserMenu\n * renderTrigger={({ displayName }) => <span>{displayName}</span>}\n * renderMenu={({ signOut }) => <button onClick={signOut}>Sign Out</button>}\n * />\n * ```\n */\nexport function UserMenu({ renderTrigger, renderMenu, className }: UserMenuProps) {\n const { user, signOut, isLoading } = useAuth()\n\n if (isLoading) {\n return (\n <div className={className}>\n <div className=\"flex items-center gap-2 p-2\">\n <div className=\"h-8 w-8 animate-pulse rounded-full bg-muted\" />\n </div>\n </div>\n )\n }\n\n if (!user) {\n return null\n }\n\n const displayName = user.firstName\n ? `${user.firstName}${user.lastName ? ` ${user.lastName}` : ''}`\n : user.email\n\n const initials = getInitials(\n user.firstName ? `${user.firstName} ${user.lastName ?? ''}` : user.email\n )\n\n const triggerProps = { user, displayName, initials }\n const menuProps = { user, displayName, initials, signOut }\n\n // If no render functions provided, render a basic menu\n if (!renderTrigger && !renderMenu) {\n return (\n <div className={className}>\n <div className=\"flex items-center gap-2 p-2\">\n <div className=\"h-8 w-8 rounded-full bg-muted flex items-center justify-center text-sm font-medium\">\n {user.profilePictureUrl ? (\n <img\n src={user.profilePictureUrl}\n alt={displayName}\n className=\"h-full w-full rounded-full object-cover\"\n />\n ) : (\n initials\n )}\n </div>\n <div className=\"text-sm\">\n <p className=\"font-medium\">{displayName}</p>\n <p className=\"text-muted-foreground text-xs\">{user.email}</p>\n </div>\n <button\n type=\"button\"\n onClick={() => signOut()}\n className=\"ml-auto text-sm text-muted-foreground hover:text-foreground\"\n >\n Sign out\n </button>\n </div>\n </div>\n )\n }\n\n return (\n <div className={className}>\n {renderTrigger?.(triggerProps)}\n {renderMenu?.(menuProps)}\n </div>\n )\n}\n","'use client'\n\nimport { useAuth } from '@workos-inc/authkit-react'\nimport { OrganizationSwitcher } from '@workos-inc/widgets'\nimport type { ReactNode } from 'react'\n\nexport interface TeamSwitcherProps {\n /**\n * Render function for the wrapper when in an organization.\n * The OrganizationSwitcher widget will be rendered inside this wrapper.\n */\n renderWrapper?: (children: ReactNode) => ReactNode\n /**\n * Render function for when there is no organization.\n * If not provided, returns null.\n */\n renderNoOrganization?: () => ReactNode\n /** CSS class name for the organization switcher wrapper */\n className?: string\n}\n\n/**\n * TeamSwitcher component that uses WorkOS authentication.\n *\n * Shows the WorkOS OrganizationSwitcher widget when authenticated with an organization,\n * or a custom \"no organization\" component when not.\n *\n * This is a headless component - you provide render functions for the UI.\n * For a pre-built sidebar menu version, use your design system's sidebar components.\n *\n * @example\n * ```tsx\n * import { TeamSwitcher } from '@mdxui/auth'\n * import { SidebarMenu, SidebarMenuItem } from '@mdxui/primitives/sidebar'\n * import { Building2 } from 'lucide-react'\n *\n * function MyTeamSwitcher() {\n * return (\n * <TeamSwitcher\n * renderWrapper={(children) => (\n * <SidebarMenu>\n * <SidebarMenuItem>\n * <div className=\"organization-switcher-wrapper\">\n * {children}\n * </div>\n * </SidebarMenuItem>\n * </SidebarMenu>\n * )}\n * renderNoOrganization={() => (\n * <SidebarMenu>\n * <SidebarMenuItem>\n * <div className=\"flex items-center gap-2\">\n * <Building2 className=\"size-4\" />\n * <span>No Organization</span>\n * </div>\n * </SidebarMenuItem>\n * </SidebarMenu>\n * )}\n * />\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Simple usage without custom rendering\n * <TeamSwitcher className=\"my-org-switcher\" />\n * ```\n */\nexport function TeamSwitcher({\n renderWrapper,\n renderNoOrganization,\n className,\n}: TeamSwitcherProps) {\n const { getAccessToken, switchToOrganization, organizationId } = useAuth()\n\n // No organization - show custom component or null\n if (!organizationId) {\n return renderNoOrganization?.() ?? null\n }\n\n // Adapt switchToOrganization to the widget's expected signature\n const handleSwitchOrganization = ({\n organizationId,\n }: {\n organizationId: string\n }) => {\n return switchToOrganization({ organizationId })\n }\n\n // Render the OrganizationSwitcher widget with required wrapper class for styling\n const widget = (\n <div className={`organization-switcher-wrapper ${className ?? ''}`}>\n <OrganizationSwitcher\n authToken={getAccessToken}\n switchToOrganization={handleSwitchOrganization}\n />\n </div>\n )\n\n // Wrap in custom wrapper if provided\n return renderWrapper ? renderWrapper(widget) : widget\n}\n"],"mappings":";AAEA,SAAS,eAAe;AAoDpB;AAfG,SAAS,aAAa;AAAA,EAC3B,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAsB;AACpB,QAAM,EAAE,QAAQ,UAAU,IAAI,QAAQ;AAEtC,QAAM,cAAc,MAAM;AACxB,eAAW;AACX,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,SAAS;AAAA,MACT,UAAU,YAAY;AAAA,MACtB,WACE,aACA;AAAA,MAED,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;;;ACjEA,SAAS,WAAAA,gBAAe;AAyDpB,gBAAAC,YAAA;AAfG,SAAS,cAAc;AAAA,EAC5B,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,QAAM,EAAE,SAAS,UAAU,IAAID,SAAQ;AAEvC,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uth","jsx","organizationId"]}
@@ -0,0 +1,42 @@
1
+ export { useAuth } from '@workos-inc/authkit-react';
2
+ import { U as UseWidgetTokenOptions, b as UseWidgetTokenResult } from '../auth-Ba2f778e.js';
3
+ import 'react';
4
+
5
+ /**
6
+ * Hook to fetch authorization tokens for WorkOS widgets
7
+ *
8
+ * Use this hook when you need to fetch widget tokens from a backend endpoint,
9
+ * typically for server-side auth scenarios. For client-side AuthKit usage,
10
+ * you can use `getAccessToken` from `useAuth()` directly with widgets.
11
+ *
12
+ * @param options - Options for token fetching
13
+ * @param options.widget - The widget type (user-profile, user-security, api-keys, etc.)
14
+ * @param options.organizationId - Optional organization context
15
+ * @param options.endpoint - Custom endpoint (default: /api/workos/widget-token)
16
+ * @returns Token state and refetch function
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * // Server-side token fetching (via backend endpoint)
21
+ * const { token, loading, error } = useWidgetToken({
22
+ * widget: 'user-profile',
23
+ * })
24
+ *
25
+ * if (loading) return <Spinner />
26
+ * if (error) return <Error message={error} />
27
+ * return <UserProfile authToken={token!} />
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * // Client-side AuthKit (recommended - no backend needed)
33
+ * import { useAuth } from '@mdxui/auth'
34
+ * import { UserProfile } from '@mdxui/auth/widgets'
35
+ *
36
+ * const { getAccessToken } = useAuth()
37
+ * return <UserProfile authToken={getAccessToken} />
38
+ * ```
39
+ */
40
+ declare function useWidgetToken({ widget, organizationId, endpoint, }: UseWidgetTokenOptions): UseWidgetTokenResult;
41
+
42
+ export { useWidgetToken };
@@ -0,0 +1,43 @@
1
+ // src/hooks/use-auth.ts
2
+ import { useAuth } from "@workos-inc/authkit-react";
3
+
4
+ // src/hooks/use-widget-token.ts
5
+ import { useCallback, useEffect, useState } from "react";
6
+ function useWidgetToken({
7
+ widget,
8
+ organizationId,
9
+ endpoint = "/api/workos/widget-token"
10
+ }) {
11
+ const [token, setToken] = useState(null);
12
+ const [loading, setLoading] = useState(true);
13
+ const [error, setError] = useState(null);
14
+ const fetchToken = useCallback(async () => {
15
+ try {
16
+ setLoading(true);
17
+ setError(null);
18
+ const params = new URLSearchParams({ widget });
19
+ if (organizationId) {
20
+ params.set("organizationId", organizationId);
21
+ }
22
+ const response = await fetch(`${endpoint}?${params}`);
23
+ const data = await response.json();
24
+ if (!response.ok) {
25
+ throw new Error(data.error || "Failed to fetch token");
26
+ }
27
+ setToken(data.token);
28
+ } catch (err) {
29
+ setError(err instanceof Error ? err.message : "Token fetch failed");
30
+ } finally {
31
+ setLoading(false);
32
+ }
33
+ }, [widget, organizationId, endpoint]);
34
+ useEffect(() => {
35
+ fetchToken();
36
+ }, [fetchToken]);
37
+ return { token, loading, error, refetch: fetchToken };
38
+ }
39
+ export {
40
+ useAuth,
41
+ useWidgetToken
42
+ };
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/use-auth.ts","../../src/hooks/use-widget-token.ts"],"sourcesContent":["'use client'\n\n/**\n * Re-export useAuth from WorkOS AuthKit\n *\n * This hook provides access to the authentication state and methods:\n * - user: The authenticated user object\n * - isLoading: Whether auth state is being loaded\n * - signIn: Function to initiate sign in\n * - signOut: Function to sign out\n * - getAccessToken: Function to get the current access token\n * - organizationId: Current organization ID (if in org context)\n * - permissions: User's permissions array\n *\n * @example\n * ```tsx\n * import { useAuth } from '@mdxui/auth'\n *\n * function MyComponent() {\n * const { user, isLoading, signIn, signOut, getAccessToken } = useAuth()\n *\n * if (isLoading) return <div>Loading...</div>\n * if (!user) return <button onClick={() => signIn()}>Sign In</button>\n *\n * return (\n * <div>\n * <p>Hello, {user.firstName}!</p>\n * <button onClick={() => signOut()}>Sign Out</button>\n * </div>\n * )\n * }\n * ```\n */\nexport { useAuth } from '@workos-inc/authkit-react'\n","'use client'\n\nimport { useCallback, useEffect, useState } from 'react'\nimport type { UseWidgetTokenOptions, UseWidgetTokenResult } from '../types/auth'\n\n/**\n * Hook to fetch authorization tokens for WorkOS widgets\n *\n * Use this hook when you need to fetch widget tokens from a backend endpoint,\n * typically for server-side auth scenarios. For client-side AuthKit usage,\n * you can use `getAccessToken` from `useAuth()` directly with widgets.\n *\n * @param options - Options for token fetching\n * @param options.widget - The widget type (user-profile, user-security, api-keys, etc.)\n * @param options.organizationId - Optional organization context\n * @param options.endpoint - Custom endpoint (default: /api/workos/widget-token)\n * @returns Token state and refetch function\n *\n * @example\n * ```tsx\n * // Server-side token fetching (via backend endpoint)\n * const { token, loading, error } = useWidgetToken({\n * widget: 'user-profile',\n * })\n *\n * if (loading) return <Spinner />\n * if (error) return <Error message={error} />\n * return <UserProfile authToken={token!} />\n * ```\n *\n * @example\n * ```tsx\n * // Client-side AuthKit (recommended - no backend needed)\n * import { useAuth } from '@mdxui/auth'\n * import { UserProfile } from '@mdxui/auth/widgets'\n *\n * const { getAccessToken } = useAuth()\n * return <UserProfile authToken={getAccessToken} />\n * ```\n */\nexport function useWidgetToken({\n widget,\n organizationId,\n endpoint = '/api/workos/widget-token',\n}: UseWidgetTokenOptions): UseWidgetTokenResult {\n const [token, setToken] = useState<string | null>(null)\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState<string | null>(null)\n\n const fetchToken = useCallback(async () => {\n try {\n setLoading(true)\n setError(null)\n\n const params = new URLSearchParams({ widget })\n if (organizationId) {\n params.set('organizationId', organizationId)\n }\n\n const response = await fetch(`${endpoint}?${params}`)\n const data = await response.json()\n\n if (!response.ok) {\n throw new Error(data.error || 'Failed to fetch token')\n }\n\n setToken(data.token)\n } catch (err) {\n setError(err instanceof Error ? err.message : 'Token fetch failed')\n } finally {\n setLoading(false)\n }\n }, [widget, organizationId, endpoint])\n\n useEffect(() => {\n fetchToken()\n }, [fetchToken])\n\n return { token, loading, error, refetch: fetchToken }\n}\n"],"mappings":";AAiCA,SAAS,eAAe;;;AC/BxB,SAAS,aAAa,WAAW,gBAAgB;AAsC1C,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAAgD;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AACtD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AAEtD,QAAM,aAAa,YAAY,YAAY;AACzC,QAAI;AACF,iBAAW,IAAI;AACf,eAAS,IAAI;AAEb,YAAM,SAAS,IAAI,gBAAgB,EAAE,OAAO,CAAC;AAC7C,UAAI,gBAAgB;AAClB,eAAO,IAAI,kBAAkB,cAAc;AAAA,MAC7C;AAEA,YAAM,WAAW,MAAM,MAAM,GAAG,QAAQ,IAAI,MAAM,EAAE;AACpD,YAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,IAAI,MAAM,KAAK,SAAS,uBAAuB;AAAA,MACvD;AAEA,eAAS,KAAK,KAAK;AAAA,IACrB,SAAS,KAAK;AACZ,eAAS,eAAe,QAAQ,IAAI,UAAU,oBAAoB;AAAA,IACpE,UAAE;AACA,iBAAW,KAAK;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,QAAQ,gBAAgB,QAAQ,CAAC;AAErC,YAAU,MAAM;AACd,eAAW;AAAA,EACb,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO,EAAE,OAAO,SAAS,OAAO,SAAS,WAAW;AACtD;","names":[]}
@@ -0,0 +1,159 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { I as IdentityProviderProps, A as AuthGateProps, W as WidgetsProviderProps } from './auth-Ba2f778e.js';
3
+
4
+ /**
5
+ * Identity provider that wraps your app with WorkOS AuthKit authentication.
6
+ *
7
+ * This provider sets up authentication context for your application and
8
+ * automatically includes the WidgetsProvider for WorkOS widgets.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * import { IdentityProvider } from '@mdxui/auth'
13
+ *
14
+ * function App() {
15
+ * return (
16
+ * <IdentityProvider
17
+ * clientId="client_xxx"
18
+ * devMode={process.env.NODE_ENV === 'development'}
19
+ * >
20
+ * <YourApp />
21
+ * </IdentityProvider>
22
+ * )
23
+ * }
24
+ * ```
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * // With custom redirect URI
29
+ * <IdentityProvider
30
+ * clientId="client_xxx"
31
+ * redirectUri="https://app.example.com/dashboard"
32
+ * onRedirectCallback={() => {
33
+ * // Custom callback after auth redirect
34
+ * }}
35
+ * >
36
+ * <YourApp />
37
+ * </IdentityProvider>
38
+ * ```
39
+ */
40
+ declare function IdentityProvider({ clientId, apiHostname, devMode, redirectUri, onRedirectCallback, children, }: IdentityProviderProps): react_jsx_runtime.JSX.Element;
41
+ /**
42
+ * Minimal identity provider without WidgetsProvider
43
+ *
44
+ * Use this if you want to set up widgets separately or don't need them.
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * import { IdentityProviderMinimal, WidgetsProvider } from '@mdxui/auth'
49
+ *
50
+ * function App() {
51
+ * return (
52
+ * <IdentityProviderMinimal clientId="client_xxx">
53
+ * <WidgetsProvider appearance="dark">
54
+ * <YourApp />
55
+ * </WidgetsProvider>
56
+ * </IdentityProviderMinimal>
57
+ * )
58
+ * }
59
+ * ```
60
+ */
61
+ declare function IdentityProviderMinimal({ clientId, apiHostname, devMode, redirectUri, onRedirectCallback, children, }: IdentityProviderProps): react_jsx_runtime.JSX.Element;
62
+
63
+ /**
64
+ * AuthGate handles authentication state and shows appropriate UI:
65
+ * - Loading state while checking auth
66
+ * - Landing page or redirect when not authenticated
67
+ * - Children (protected content) when authenticated
68
+ *
69
+ * @example
70
+ * ```tsx
71
+ * import { AuthGate } from '@mdxui/auth'
72
+ *
73
+ * function App() {
74
+ * return (
75
+ * <AuthGate>
76
+ * <ProtectedDashboard />
77
+ * </AuthGate>
78
+ * )
79
+ * }
80
+ * ```
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * // With custom components
85
+ * <AuthGate
86
+ * loadingComponent={<CustomSpinner />}
87
+ * landingComponent={<CustomLandingPage />}
88
+ * >
89
+ * <Dashboard />
90
+ * </AuthGate>
91
+ * ```
92
+ *
93
+ * @example
94
+ * ```tsx
95
+ * // Allow unauthenticated access
96
+ * <AuthGate required={false}>
97
+ * <PublicContent />
98
+ * </AuthGate>
99
+ * ```
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * // Redirect to external URL when not authenticated
104
+ * <AuthGate
105
+ * onUnauthenticated="redirect"
106
+ * redirectUrl="https://marketing.example.com"
107
+ * >
108
+ * <Dashboard />
109
+ * </AuthGate>
110
+ * ```
111
+ */
112
+ declare function AuthGate({ children, required, loadingComponent, landingComponent, onUnauthenticated, redirectUrl, }: AuthGateProps): react_jsx_runtime.JSX.Element;
113
+
114
+ /**
115
+ * Hook to detect dark mode from document class or system preference
116
+ *
117
+ * @returns Object with isDark state and mounted flag
118
+ *
119
+ * @example
120
+ * ```tsx
121
+ * const { isDark, mounted } = useThemeDetection()
122
+ * const appearance = mounted ? (isDark ? 'dark' : 'light') : 'inherit'
123
+ * ```
124
+ */
125
+ declare function useThemeDetection(): {
126
+ isDark: boolean;
127
+ mounted: boolean;
128
+ };
129
+ /**
130
+ * Provider for WorkOS widgets with automatic theme detection
131
+ *
132
+ * Wraps children with WorkOsWidgets context and automatically detects
133
+ * light/dark mode from document classes or system preference.
134
+ *
135
+ * @example
136
+ * ```tsx
137
+ * import { WidgetsProvider } from '@mdxui/auth'
138
+ * import { UserProfile } from '@mdxui/auth/widgets'
139
+ *
140
+ * function App() {
141
+ * return (
142
+ * <WidgetsProvider>
143
+ * <UserProfile authToken={getAccessToken} />
144
+ * </WidgetsProvider>
145
+ * )
146
+ * }
147
+ * ```
148
+ *
149
+ * @example
150
+ * ```tsx
151
+ * // With explicit theme
152
+ * <WidgetsProvider appearance="dark" radius="large">
153
+ * <UserProfile authToken={token} />
154
+ * </WidgetsProvider>
155
+ * ```
156
+ */
157
+ declare function WidgetsProvider({ children, appearance, radius, scaling, }: WidgetsProviderProps): react_jsx_runtime.JSX.Element;
158
+
159
+ export { AuthGate as A, IdentityProvider as I, WidgetsProvider as W, IdentityProviderMinimal as a, useThemeDetection as u };
@@ -0,0 +1,12 @@
1
+ export { A as AuthGate, I as IdentityProvider, a as IdentityProviderMinimal, W as WidgetsProvider, u as useThemeDetection } from './index-Bl4BwORF.js';
2
+ export { ApiKeys, OrganizationSwitcher, Pipes, UserProfile, UserSecurity, UserSessions, UsersManagement } from './widgets/index.js';
3
+ export { SignInButton, SignOutButton, TeamSwitcher, UserMenu } from './components/index.js';
4
+ export { useAuth } from '@workos-inc/authkit-react';
5
+ export { useWidgetToken } from './hooks/index.js';
6
+ export { A as AuthGateProps, a as AuthToken, B as BaseWidgetProps, I as IdentityProviderProps, O as OrganizationWidgetProps, U as UseWidgetTokenOptions, b as UseWidgetTokenResult, W as WidgetsProviderProps } from './auth-Ba2f778e.js';
7
+ export { a as AuthOrganization, e as AuthOrganizationSchema, b as AuthSession, d as AuthSessionSchema, A as AuthUser, c as AuthUserSchema, I as Impersonator, f as ImpersonatorSchema } from './auth-organization-CN1WpGnL.js';
8
+ export { AppearanceSchema, AuthGatePropsSchema, AuthTokenSchema, BaseWidgetPropsSchema, IdentityProviderPropsSchema, OrganizationWidgetPropsSchema, RadiusSchema, ScalingSchema, UnauthenticatedActionSchema, UseWidgetTokenOptionsSchema, UseWidgetTokenResultSchema, WidgetsProviderPropsSchema } from './schemas/index.js';
9
+ import 'react/jsx-runtime';
10
+ import 'react';
11
+ import 'zod/v4/core';
12
+ import 'zod';