Skip to content

Commit e676fa3

Browse files
committed
add key validation and fix credentials auth for deleteapikey method
1 parent 6e51252 commit e676fa3

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

‎src/lib/auth.ts‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class AuthAPI {
171171
headers['X-User-Password'] = credentials.password;
172172
}
173173

174-
const response = await this.internalApi.authControllerGetAllApiKeys(
174+
return this.internalApi.authControllerGetAllApiKeys(
175175
{
176176
offset,
177177
limit,
@@ -186,7 +186,6 @@ export class AuthAPI {
186186
headers: { ...(init.headers as Record<string, string>), ...headers },
187187
})
188188
);
189-
return response;
190189
}
191190

192191
async deleteApiKeyById(options: {
@@ -195,10 +194,7 @@ export class AuthAPI {
195194
}): Promise<{ success: boolean }> {
196195
const { keyId, credentials } = options;
197196
validateUserCredentials(credentials);
198-
const authorization =
199-
typeof credentials === 'string'
200-
? `Bearer ${credentials}`
201-
: credentials.email;
197+
validateString(keyId, 'The key ID must be nonempty');
202198

203199
const headers: Record<string, string> = {};
204200
if (typeof credentials === 'string') {
@@ -208,17 +204,21 @@ export class AuthAPI {
208204
headers['X-User-Password'] = credentials.password;
209205
}
210206

211-
try {
212-
await this.internalApi.authControllerDeleteApiKeyById(
213-
{ id: keyId, authorization } as any,
214-
async ({ init }) => ({
215-
headers: { ...(init.headers as Record<string, string>), ...headers },
216-
})
217-
);
218-
return { success: true };
219-
} catch {
220-
return { success: false };
221-
}
207+
await this.internalApi.authControllerDeleteApiKeyById(
208+
{
209+
id: keyId,
210+
...(typeof credentials === 'string'
211+
? { xUserJwt: credentials }
212+
: {
213+
xUserEmail: credentials.email,
214+
xUserPassword: credentials.password,
215+
}),
216+
},
217+
async ({ init }) => ({
218+
headers: { ...(init.headers as Record<string, string>), ...headers },
219+
})
220+
);
221+
return { success: true };
222222
}
223223

224224
async deleteAccountRequest(options: {

0 commit comments

Comments
 (0)