@lukoweb/apitogo 0.1.1 → 0.1.3

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.
Files changed (91) hide show
  1. package/dist/cli/cli.js +168 -57
  2. package/dist/declarations/lib/ui/Command.d.ts +1 -1
  3. package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
  4. package/package.json +2 -1
  5. package/src/app/main.tsx +150 -150
  6. package/src/config/loader.ts +245 -245
  7. package/src/index.ts +33 -33
  8. package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
  9. package/src/lib/authentication/components/SignIn.tsx +46 -46
  10. package/src/lib/authentication/components/SignUp.tsx +48 -48
  11. package/src/lib/authentication/providers/clerk.tsx +224 -224
  12. package/src/lib/authentication/ui/AuthCard.tsx +7 -7
  13. package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
  14. package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
  15. package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
  16. package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
  17. package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
  18. package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
  19. package/src/lib/components/Autocomplete.tsx +123 -123
  20. package/src/lib/components/DeveloperHint.tsx +39 -35
  21. package/src/lib/components/Header.tsx +260 -260
  22. package/src/lib/components/Layout.tsx +53 -53
  23. package/src/lib/components/Main.tsx +51 -51
  24. package/src/lib/components/Mermaid.tsx +74 -70
  25. package/src/lib/components/MobileTopNavigation.tsx +276 -276
  26. package/src/lib/components/MultiSelect.tsx +86 -82
  27. package/src/lib/components/TopNavigation.tsx +103 -103
  28. package/src/lib/components/index.ts +26 -26
  29. package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
  30. package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
  31. package/src/lib/components/navigation/NavigationItem.tsx +181 -177
  32. package/src/lib/core/RouteGuard.tsx +193 -193
  33. package/src/lib/errors/ErrorMessage.tsx +50 -46
  34. package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
  35. package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
  36. package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
  37. package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
  38. package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
  39. package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
  40. package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
  41. package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
  42. package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
  43. package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
  44. package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
  45. package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
  46. package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
  47. package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
  48. package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
  49. package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
  50. package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
  51. package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
  52. package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
  53. package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
  54. package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
  55. package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
  56. package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
  57. package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
  58. package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
  59. package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
  60. package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
  61. package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
  62. package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
  63. package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
  64. package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
  65. package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
  66. package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
  67. package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
  68. package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
  69. package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
  70. package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
  71. package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
  72. package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
  73. package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
  74. package/src/lib/ui/ActionButton.tsx +21 -21
  75. package/src/lib/ui/Command.tsx +191 -191
  76. package/src/lib/util/MdxComponents.tsx +150 -150
  77. package/src/vite/config.ts +234 -231
  78. package/src/vite/dev-server.ts +291 -291
  79. package/src/vite/plugin-api-keys.ts +50 -50
  80. package/src/vite/plugin-api.ts +320 -318
  81. package/src/vite/plugin-auth.ts +38 -38
  82. package/src/vite/plugin-component.ts +45 -39
  83. package/src/vite/plugin-config.ts +75 -75
  84. package/src/vite/plugin-custom-pages.ts +36 -36
  85. package/src/vite/plugin-docs.ts +202 -202
  86. package/src/vite/plugin-markdown-export.ts +214 -214
  87. package/src/vite/plugin-mdx.ts +149 -149
  88. package/src/vite/plugin-navigation.ts +106 -106
  89. package/src/vite/plugin-search.ts +47 -47
  90. package/src/vite/plugin.ts +42 -42
  91. package/src/vite/prerender/prerender.ts +233 -233
@@ -1,46 +1,46 @@
1
- import { useEffect } from "react";
2
- import { useSearchParams } from "react-router";
3
- import { Spinner } from "@lukoweb/apitogo/components";
4
- import {
5
- Card,
6
- CardContent,
7
- CardDescription,
8
- CardHeader,
9
- CardTitle,
10
- } from "@lukoweb/apitogo/ui/Card.js";
11
- import { useLatest } from "../../util/useLatest.js";
12
- import { useAuth } from "../hook.js";
13
-
14
- export const SignIn = () => {
15
- const auth = useAuth();
16
- const [search] = useSearchParams();
17
- const redirectTo = search.get("redirect") ?? undefined;
18
-
19
- const login = useLatest(auth.login);
20
-
21
- useEffect(() => {
22
- void login.current({
23
- redirectTo: redirectTo ?? "/",
24
- replace: true,
25
- });
26
- }, [login, redirectTo]);
27
-
28
- return (
29
- <div className="flex items-center justify-center mt-8">
30
- <Card className="max-w-md w-full">
31
- <CardHeader>
32
- <CardTitle className="text-lg">Sign in</CardTitle>
33
- <CardDescription>
34
- You're being redirected to our secure login provider to complete
35
- your sign-in process.
36
- </CardDescription>
37
- </CardHeader>
38
- <CardContent>
39
- <div className="flex items-center text-sm font-medium gap-2">
40
- <Spinner /> Redirecting...
41
- </div>
42
- </CardContent>
43
- </Card>
44
- </div>
45
- );
46
- };
1
+ import { Spinner } from "@lukoweb/apitogo/components";
2
+ import {
3
+ Card,
4
+ CardContent,
5
+ CardDescription,
6
+ CardHeader,
7
+ CardTitle,
8
+ } from "@lukoweb/apitogo/ui/Card.js";
9
+ import { useEffect } from "react";
10
+ import { useSearchParams } from "react-router";
11
+ import { useLatest } from "../../util/useLatest.js";
12
+ import { useAuth } from "../hook.js";
13
+
14
+ export const SignIn = () => {
15
+ const auth = useAuth();
16
+ const [search] = useSearchParams();
17
+ const redirectTo = search.get("redirect") ?? undefined;
18
+
19
+ const login = useLatest(auth.login);
20
+
21
+ useEffect(() => {
22
+ void login.current({
23
+ redirectTo: redirectTo ?? "/",
24
+ replace: true,
25
+ });
26
+ }, [login, redirectTo]);
27
+
28
+ return (
29
+ <div className="flex items-center justify-center mt-8">
30
+ <Card className="max-w-md w-full">
31
+ <CardHeader>
32
+ <CardTitle className="text-lg">Sign in</CardTitle>
33
+ <CardDescription>
34
+ You're being redirected to our secure login provider to complete
35
+ your sign-in process.
36
+ </CardDescription>
37
+ </CardHeader>
38
+ <CardContent>
39
+ <div className="flex items-center text-sm font-medium gap-2">
40
+ <Spinner /> Redirecting...
41
+ </div>
42
+ </CardContent>
43
+ </Card>
44
+ </div>
45
+ );
46
+ };
@@ -1,48 +1,48 @@
1
- import { useEffect } from "react";
2
- import { useSearchParams } from "react-router";
3
- import { Button, Link } from "@lukoweb/apitogo/components";
4
- import {
5
- Card,
6
- CardContent,
7
- CardDescription,
8
- CardHeader,
9
- CardTitle,
10
- } from "@lukoweb/apitogo/ui/Card.js";
11
- import { useLatest } from "../../util/useLatest.js";
12
- import { useAuth } from "../hook.js";
13
-
14
- export const SignUp = () => {
15
- const auth = useAuth();
16
- const [search] = useSearchParams();
17
- const redirectTo = search.get("redirect") ?? "/";
18
-
19
- const signup = useLatest(auth.signup);
20
-
21
- useEffect(() => {
22
- void signup.current({ redirectTo });
23
- }, [signup, redirectTo]);
24
-
25
- return (
26
- <div className="flex items-center justify-center mt-8">
27
- <Card className="max-w-md w-full">
28
- <CardHeader>
29
- <CardTitle className="text-lg">Sign up</CardTitle>
30
- <CardDescription>
31
- You're being redirected to our secure login provider to complete
32
- your sign up process.
33
- </CardDescription>
34
- </CardHeader>
35
- <CardContent>
36
- <div className="flex flex-col gap-2 justify-center">
37
- <Button onClick={() => auth.signup()} variant="default">
38
- Register
39
- </Button>
40
- <Button variant="link" className="text-muted-foreground" asChild>
41
- <Link to="/">Go home</Link>
42
- </Button>
43
- </div>
44
- </CardContent>
45
- </Card>
46
- </div>
47
- );
48
- };
1
+ import { Button, Link } from "@lukoweb/apitogo/components";
2
+ import {
3
+ Card,
4
+ CardContent,
5
+ CardDescription,
6
+ CardHeader,
7
+ CardTitle,
8
+ } from "@lukoweb/apitogo/ui/Card.js";
9
+ import { useEffect } from "react";
10
+ import { useSearchParams } from "react-router";
11
+ import { useLatest } from "../../util/useLatest.js";
12
+ import { useAuth } from "../hook.js";
13
+
14
+ export const SignUp = () => {
15
+ const auth = useAuth();
16
+ const [search] = useSearchParams();
17
+ const redirectTo = search.get("redirect") ?? "/";
18
+
19
+ const signup = useLatest(auth.signup);
20
+
21
+ useEffect(() => {
22
+ void signup.current({ redirectTo });
23
+ }, [signup, redirectTo]);
24
+
25
+ return (
26
+ <div className="flex items-center justify-center mt-8">
27
+ <Card className="max-w-md w-full">
28
+ <CardHeader>
29
+ <CardTitle className="text-lg">Sign up</CardTitle>
30
+ <CardDescription>
31
+ You're being redirected to our secure login provider to complete
32
+ your sign up process.
33
+ </CardDescription>
34
+ </CardHeader>
35
+ <CardContent>
36
+ <div className="flex flex-col gap-2 justify-center">
37
+ <Button onClick={() => auth.signup()} variant="default">
38
+ Register
39
+ </Button>
40
+ <Button variant="link" className="text-muted-foreground" asChild>
41
+ <Link to="/">Go home</Link>
42
+ </Button>
43
+ </div>
44
+ </CardContent>
45
+ </Card>
46
+ </div>
47
+ );
48
+ };
@@ -1,224 +1,224 @@
1
- import type { Clerk } from "@clerk/clerk-js";
2
- import type { ZudokuPlugin } from "@lukoweb/apitogo/plugins";
3
- import type { ClerkAuthenticationConfig } from "../../../config/config.js";
4
- import type {
5
- AuthActionContext,
6
- AuthenticationPlugin,
7
- AuthenticationProviderInitializer,
8
- } from "../authentication.js";
9
- import { SignIn } from "../components/SignIn.js";
10
- import { SignOut } from "../components/SignOut.js";
11
- import { SignUp } from "../components/SignUp.js";
12
- import { type UserProfile, useAuthState } from "../state.js";
13
- import { getClerkFrontendApi } from "./util.js";
14
-
15
- export type ClerkProviderData = {
16
- type: "clerk";
17
- user: NonNullable<Clerk["session"]>["user"] | undefined;
18
- };
19
-
20
- declare module "../state.js" {
21
- interface ProviderDataRegistry {
22
- clerk: ClerkProviderData;
23
- }
24
- }
25
-
26
- let clerkPromise: Promise<Clerk> | undefined;
27
-
28
- const loadClerk = (publishableKey: string): Promise<Clerk> => {
29
- if (clerkPromise) return clerkPromise;
30
-
31
- clerkPromise = new Promise<void>((resolve, reject) => {
32
- const frontendApiUrl = getClerkFrontendApi(publishableKey);
33
-
34
- const script = document.createElement("script");
35
- script.src = `https://${frontendApiUrl}/npm/@clerk/clerk-js@5/dist/clerk.browser.js`;
36
- script.async = true;
37
- script.crossOrigin = "anonymous";
38
- script.dataset.clerkPublishableKey = publishableKey;
39
- script.onload = () => resolve();
40
- script.onerror = () => {
41
- clerkPromise = undefined;
42
- reject(new Error("Failed to load Clerk from CDN"));
43
- };
44
- document.head.appendChild(script);
45
- }).then(async () => {
46
- const clerk = (window as { Clerk?: Clerk }).Clerk;
47
- if (!clerk) {
48
- throw new Error("Clerk script loaded but window.Clerk is not available");
49
- }
50
- await clerk.load();
51
- return clerk;
52
- });
53
-
54
- return clerkPromise;
55
- };
56
-
57
- const clerkAuth: AuthenticationProviderInitializer<
58
- ClerkAuthenticationConfig
59
- > = ({
60
- clerkPubKey,
61
- jwtTemplateName,
62
- redirectToAfterSignOut = "/",
63
- redirectToAfterSignUp,
64
- redirectToAfterSignIn,
65
- }): AuthenticationPlugin & ZudokuPlugin => {
66
- const getClerk = (): Promise<Clerk> => {
67
- if (typeof window === "undefined") {
68
- return Promise.reject(new Error("Clerk is not available during SSR"));
69
- }
70
- return loadClerk(clerkPubKey);
71
- };
72
-
73
- async function getAccessToken() {
74
- const clerk = await getClerk();
75
-
76
- if (!clerk.session) {
77
- throw new Error("No session available");
78
- }
79
- const response = await clerk.session.getToken({
80
- template: jwtTemplateName,
81
- });
82
- if (!response) {
83
- throw new Error("Could not get access token from Clerk");
84
- }
85
- return response;
86
- }
87
-
88
- async function getUserProfile(
89
- clerk: Clerk,
90
- ): Promise<UserProfile | undefined> {
91
- const user = clerk.session?.user;
92
- if (!user) return undefined;
93
-
94
- const verifiedEmail = user.emailAddresses.find(
95
- (email) => email.verification.status === "verified",
96
- );
97
-
98
- return {
99
- sub: user.id ?? "",
100
- email:
101
- verifiedEmail?.emailAddress ??
102
- user.emailAddresses[0]?.emailAddress ??
103
- "",
104
- name: user.fullName ?? "",
105
- emailVerified: !!verifiedEmail?.emailAddress,
106
- pictureUrl: user.imageUrl ?? "",
107
- };
108
- }
109
-
110
- async function refreshUserProfile() {
111
- const clerk = await getClerk().catch((e) => {
112
- // biome-ignore lint/suspicious/noConsole: Intentional warning
113
- console.warn("Clerk unavailable during profile refresh:", e);
114
- return undefined;
115
- });
116
- if (!clerk) return false;
117
-
118
- await clerk.session?.user?.reload();
119
-
120
- const profile = await getUserProfile(clerk);
121
-
122
- if (!profile) {
123
- return false;
124
- }
125
-
126
- useAuthState.setState({
127
- isAuthenticated: true,
128
- isPending: false,
129
- profile,
130
- providerData: {
131
- type: "clerk",
132
- user: clerk.session?.user,
133
- },
134
- });
135
-
136
- return true;
137
- }
138
-
139
- async function signRequest(request: Request): Promise<Request> {
140
- const response = await getAccessToken();
141
- request.headers.set("Authorization", `Bearer ${response}`);
142
- return request;
143
- }
144
-
145
- return {
146
- getRoutes: () => [
147
- { path: "/signout", element: <SignOut /> },
148
- { path: "/signin", element: <SignIn /> },
149
- { path: "/signup", element: <SignUp /> },
150
- ],
151
- refreshUserProfile,
152
- getProfileMenuItems() {
153
- return [];
154
- },
155
- initialize: async () => {
156
- if (typeof window === "undefined") return;
157
-
158
- const clerk = await getClerk().catch((e) => {
159
- // biome-ignore lint/suspicious/noConsole: Intentional error logging
160
- console.error("Clerk failed to initialize:", e);
161
- return undefined;
162
- });
163
- if (!clerk) return;
164
-
165
- if (clerk.session) {
166
- const profile = await getUserProfile(clerk);
167
-
168
- if (!profile) {
169
- useAuthState.getState().setLoggedOut();
170
- return;
171
- }
172
-
173
- useAuthState.getState().setLoggedIn({
174
- profile,
175
- providerData: {
176
- type: "clerk",
177
- user: clerk.session.user,
178
- },
179
- });
180
- } else {
181
- useAuthState.getState().setLoggedOut();
182
- }
183
- },
184
- getAccessToken,
185
- signRequest,
186
- signOut: async () => {
187
- const clerk = await getClerk();
188
- useAuthState.getState().setLoggedOut();
189
- await clerk.signOut({
190
- redirectUrl: window.location.origin + redirectToAfterSignOut,
191
- });
192
- },
193
- signIn: async (
194
- _: AuthActionContext,
195
- { redirectTo }: { redirectTo?: string } = {},
196
- ) => {
197
- const clerk = await getClerk();
198
- await clerk.redirectToSignIn({
199
- signInForceRedirectUrl: redirectToAfterSignIn
200
- ? window.location.origin + redirectToAfterSignIn
201
- : redirectTo,
202
- signUpForceRedirectUrl: redirectToAfterSignUp
203
- ? window.location.origin + redirectToAfterSignUp
204
- : redirectTo,
205
- });
206
- },
207
- signUp: async (
208
- _: AuthActionContext,
209
- { redirectTo }: { redirectTo?: string } = {},
210
- ) => {
211
- const clerk = await getClerk();
212
- await clerk.redirectToSignUp({
213
- signInForceRedirectUrl: redirectToAfterSignIn
214
- ? window.location.origin + redirectToAfterSignIn
215
- : redirectTo,
216
- signUpForceRedirectUrl: redirectToAfterSignUp
217
- ? window.location.origin + redirectToAfterSignUp
218
- : redirectTo,
219
- });
220
- },
221
- };
222
- };
223
-
224
- export default clerkAuth;
1
+ import type { Clerk } from "@clerk/clerk-js";
2
+ import type { ZudokuPlugin } from "@lukoweb/apitogo/plugins";
3
+ import type { ClerkAuthenticationConfig } from "../../../config/config.js";
4
+ import type {
5
+ AuthActionContext,
6
+ AuthenticationPlugin,
7
+ AuthenticationProviderInitializer,
8
+ } from "../authentication.js";
9
+ import { SignIn } from "../components/SignIn.js";
10
+ import { SignOut } from "../components/SignOut.js";
11
+ import { SignUp } from "../components/SignUp.js";
12
+ import { type UserProfile, useAuthState } from "../state.js";
13
+ import { getClerkFrontendApi } from "./util.js";
14
+
15
+ export type ClerkProviderData = {
16
+ type: "clerk";
17
+ user: NonNullable<Clerk["session"]>["user"] | undefined;
18
+ };
19
+
20
+ declare module "../state.js" {
21
+ interface ProviderDataRegistry {
22
+ clerk: ClerkProviderData;
23
+ }
24
+ }
25
+
26
+ let clerkPromise: Promise<Clerk> | undefined;
27
+
28
+ const loadClerk = (publishableKey: string): Promise<Clerk> => {
29
+ if (clerkPromise) return clerkPromise;
30
+
31
+ clerkPromise = new Promise<void>((resolve, reject) => {
32
+ const frontendApiUrl = getClerkFrontendApi(publishableKey);
33
+
34
+ const script = document.createElement("script");
35
+ script.src = `https://${frontendApiUrl}/npm/@clerk/clerk-js@5/dist/clerk.browser.js`;
36
+ script.async = true;
37
+ script.crossOrigin = "anonymous";
38
+ script.dataset.clerkPublishableKey = publishableKey;
39
+ script.onload = () => resolve();
40
+ script.onerror = () => {
41
+ clerkPromise = undefined;
42
+ reject(new Error("Failed to load Clerk from CDN"));
43
+ };
44
+ document.head.appendChild(script);
45
+ }).then(async () => {
46
+ const clerk = (window as { Clerk?: Clerk }).Clerk;
47
+ if (!clerk) {
48
+ throw new Error("Clerk script loaded but window.Clerk is not available");
49
+ }
50
+ await clerk.load();
51
+ return clerk;
52
+ });
53
+
54
+ return clerkPromise;
55
+ };
56
+
57
+ const clerkAuth: AuthenticationProviderInitializer<
58
+ ClerkAuthenticationConfig
59
+ > = ({
60
+ clerkPubKey,
61
+ jwtTemplateName,
62
+ redirectToAfterSignOut = "/",
63
+ redirectToAfterSignUp,
64
+ redirectToAfterSignIn,
65
+ }): AuthenticationPlugin & ZudokuPlugin => {
66
+ const getClerk = (): Promise<Clerk> => {
67
+ if (typeof window === "undefined") {
68
+ return Promise.reject(new Error("Clerk is not available during SSR"));
69
+ }
70
+ return loadClerk(clerkPubKey);
71
+ };
72
+
73
+ async function getAccessToken() {
74
+ const clerk = await getClerk();
75
+
76
+ if (!clerk.session) {
77
+ throw new Error("No session available");
78
+ }
79
+ const response = await clerk.session.getToken({
80
+ template: jwtTemplateName,
81
+ });
82
+ if (!response) {
83
+ throw new Error("Could not get access token from Clerk");
84
+ }
85
+ return response;
86
+ }
87
+
88
+ async function getUserProfile(
89
+ clerk: Clerk,
90
+ ): Promise<UserProfile | undefined> {
91
+ const user = clerk.session?.user;
92
+ if (!user) return undefined;
93
+
94
+ const verifiedEmail = user.emailAddresses.find(
95
+ (email) => email.verification.status === "verified",
96
+ );
97
+
98
+ return {
99
+ sub: user.id ?? "",
100
+ email:
101
+ verifiedEmail?.emailAddress ??
102
+ user.emailAddresses[0]?.emailAddress ??
103
+ "",
104
+ name: user.fullName ?? "",
105
+ emailVerified: !!verifiedEmail?.emailAddress,
106
+ pictureUrl: user.imageUrl ?? "",
107
+ };
108
+ }
109
+
110
+ async function refreshUserProfile() {
111
+ const clerk = await getClerk().catch((e) => {
112
+ // biome-ignore lint/suspicious/noConsole: Intentional warning
113
+ console.warn("Clerk unavailable during profile refresh:", e);
114
+ return undefined;
115
+ });
116
+ if (!clerk) return false;
117
+
118
+ await clerk.session?.user?.reload();
119
+
120
+ const profile = await getUserProfile(clerk);
121
+
122
+ if (!profile) {
123
+ return false;
124
+ }
125
+
126
+ useAuthState.setState({
127
+ isAuthenticated: true,
128
+ isPending: false,
129
+ profile,
130
+ providerData: {
131
+ type: "clerk",
132
+ user: clerk.session?.user,
133
+ },
134
+ });
135
+
136
+ return true;
137
+ }
138
+
139
+ async function signRequest(request: Request): Promise<Request> {
140
+ const response = await getAccessToken();
141
+ request.headers.set("Authorization", `Bearer ${response}`);
142
+ return request;
143
+ }
144
+
145
+ return {
146
+ getRoutes: () => [
147
+ { path: "/signout", element: <SignOut /> },
148
+ { path: "/signin", element: <SignIn /> },
149
+ { path: "/signup", element: <SignUp /> },
150
+ ],
151
+ refreshUserProfile,
152
+ getProfileMenuItems() {
153
+ return [];
154
+ },
155
+ initialize: async () => {
156
+ if (typeof window === "undefined") return;
157
+
158
+ const clerk = await getClerk().catch((e) => {
159
+ // biome-ignore lint/suspicious/noConsole: Intentional error logging
160
+ console.error("Clerk failed to initialize:", e);
161
+ return undefined;
162
+ });
163
+ if (!clerk) return;
164
+
165
+ if (clerk.session) {
166
+ const profile = await getUserProfile(clerk);
167
+
168
+ if (!profile) {
169
+ useAuthState.getState().setLoggedOut();
170
+ return;
171
+ }
172
+
173
+ useAuthState.getState().setLoggedIn({
174
+ profile,
175
+ providerData: {
176
+ type: "clerk",
177
+ user: clerk.session.user,
178
+ },
179
+ });
180
+ } else {
181
+ useAuthState.getState().setLoggedOut();
182
+ }
183
+ },
184
+ getAccessToken,
185
+ signRequest,
186
+ signOut: async () => {
187
+ const clerk = await getClerk();
188
+ useAuthState.getState().setLoggedOut();
189
+ await clerk.signOut({
190
+ redirectUrl: window.location.origin + redirectToAfterSignOut,
191
+ });
192
+ },
193
+ signIn: async (
194
+ _: AuthActionContext,
195
+ { redirectTo }: { redirectTo?: string } = {},
196
+ ) => {
197
+ const clerk = await getClerk();
198
+ await clerk.redirectToSignIn({
199
+ signInForceRedirectUrl: redirectToAfterSignIn
200
+ ? window.location.origin + redirectToAfterSignIn
201
+ : redirectTo,
202
+ signUpForceRedirectUrl: redirectToAfterSignUp
203
+ ? window.location.origin + redirectToAfterSignUp
204
+ : redirectTo,
205
+ });
206
+ },
207
+ signUp: async (
208
+ _: AuthActionContext,
209
+ { redirectTo }: { redirectTo?: string } = {},
210
+ ) => {
211
+ const clerk = await getClerk();
212
+ await clerk.redirectToSignUp({
213
+ signInForceRedirectUrl: redirectToAfterSignIn
214
+ ? window.location.origin + redirectToAfterSignIn
215
+ : redirectTo,
216
+ signUpForceRedirectUrl: redirectToAfterSignUp
217
+ ? window.location.origin + redirectToAfterSignUp
218
+ : redirectTo,
219
+ });
220
+ },
221
+ };
222
+ };
223
+
224
+ export default clerkAuth;
@@ -1,7 +1,7 @@
1
- import { Card } from "@lukoweb/apitogo/ui/Card.js";
2
- import createVariantComponent from "../../util/createVariantComponent.js";
3
-
4
- export const AuthCard = createVariantComponent(
5
- Card,
6
- "max-w-md w-full mt-10 mx-auto",
7
- );
1
+ import { Card } from "@lukoweb/apitogo/ui/Card.js";
2
+ import createVariantComponent from "../../util/createVariantComponent.js";
3
+
4
+ export const AuthCard = createVariantComponent(
5
+ Card,
6
+ "max-w-md w-full mt-10 mx-auto",
7
+ );