Skip to content

Commit 2ed5c1a

Browse files
committed
refactor(astro): Reuse clerk-client.ts in keyless service
Replace manual createClerkClient calls with the existing clerkClient helper, matching React Router's pattern of reusing the framework's client factory. Changes: - Import clerkClient from '../clerk-client' instead of createClerkClient from @clerk/backend - Use clerkClient(context) in createAccountlessApplication and completeOnboarding - Remove manual client configuration (secretKey, publishableKey, apiUrl, userAgent) - Client now properly inherits all configuration from getSafeEnv(context) Benefits: ✅ DRY - reuses existing client configuration logic ✅ Consistent - all API calls use same client setup ✅ Maintainable - client config changes apply everywhere ✅ Matches React Router pattern exactly ✅ Inherits telemetry, sdkMetadata, and all other configs automatically
1 parent 3bc54de commit 2ed5c1a

1 file changed

Lines changed: 5 additions & 17 deletions

File tree

  • packages/astro/src/server/keyless

packages/astro/src/server/keyless/index.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createClerkClient } from '@clerk/backend';
21
import { createKeylessService } from '@clerk/shared/keyless';
32
import type { APIContext } from 'astro';
43

4+
import { clerkClient } from '../clerk-client';
55
import type { ClerkAstroMiddlewareOptions } from '../clerk-middleware';
66
import { createFileStorage } from './file-storage.js';
77

@@ -45,14 +45,7 @@ export async function keyless(
4545
api: {
4646
async createAccountlessApplication(requestHeaders?: Headers) {
4747
try {
48-
// Reuse existing clerkClient factory with keys from process.env
49-
const client = createClerkClient({
50-
secretKey: process.env.CLERK_SECRET_KEY,
51-
publishableKey: process.env.PUBLIC_CLERK_PUBLISHABLE_KEY,
52-
apiUrl: process.env.CLERK_API_URL,
53-
userAgent: `${PACKAGE_NAME}@${PACKAGE_VERSION}`,
54-
});
55-
return await client.__experimental_accountlessApplications.createAccountlessApplication({
48+
return await clerkClient(context).__experimental_accountlessApplications.createAccountlessApplication({
5649
requestHeaders,
5750
});
5851
} catch {
@@ -61,14 +54,9 @@ export async function keyless(
6154
},
6255
async completeOnboarding(requestHeaders?: Headers) {
6356
try {
64-
// Reuse existing clerkClient factory with keys from process.env
65-
const client = createClerkClient({
66-
secretKey: process.env.CLERK_SECRET_KEY,
67-
publishableKey: process.env.PUBLIC_CLERK_PUBLISHABLE_KEY,
68-
apiUrl: process.env.CLERK_API_URL,
69-
userAgent: `${PACKAGE_NAME}@${PACKAGE_VERSION}`,
70-
});
71-
return await client.__experimental_accountlessApplications.completeAccountlessApplicationOnboarding({
57+
return await clerkClient(
58+
context,
59+
).__experimental_accountlessApplications.completeAccountlessApplicationOnboarding({
7260
requestHeaders,
7361
});
7462
} catch {

0 commit comments

Comments
 (0)