Skip to content

Commit 9e8babe

Browse files
committed
fix: use create-first API credential fallback
1 parent 3530b10 commit 9e8babe

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

packages/client/src/actions/auth.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export type CreateOrDeriveApiKeyError =
101101
| UnexpectedResponseError;
102102

103103
/**
104-
* Derives an API key and falls back to creation when one does not exist yet.
104+
* Creates an API key and falls back to derivation when it already exists.
105105
*
106106
* @remarks
107107
* This is a low-level auth action that most SDK consumers will not need.
@@ -118,14 +118,6 @@ export async function createOrDeriveApiKey(
118118
client: Client,
119119
request: L2AuthRequest,
120120
): Promise<ApiKeyCreds> {
121-
try {
122-
return await deriveApiKey(client, request);
123-
} catch (error) {
124-
if (!(error instanceof RequestRejectedError) || error.status !== 400) {
125-
throw error;
126-
}
127-
}
128-
129121
try {
130122
return await createApiKey(client, request);
131123
} catch (error) {

packages/client/src/clients.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ describe('clients', () => {
2323
await expect(fetchApiKeys(secureClient)).resolves.toBeDefined();
2424
});
2525

26+
it('authenticates twice with the same nonce', async () => {
27+
const firstClient = await publicClient
28+
.beginAuthentication({ nonce: 2 })
29+
.then(authenticateWith(walletClient));
30+
31+
await expect(fetchApiKeys(firstClient)).resolves.toBeDefined();
32+
33+
const secondClient = await publicClient
34+
.beginAuthentication({ nonce: 2 })
35+
.then(authenticateWith(walletClient));
36+
37+
await expect(fetchApiKeys(secondClient)).resolves.toBeDefined();
38+
});
39+
2640
it('reuses stored credentials during authentication when they remain valid', async () => {
2741
const initialClient = await publicClient
2842
.beginAuthentication()

0 commit comments

Comments
 (0)