({ user_id = null, name = '' } = {})
| 3380 | } |
| 3381 | |
| 3382 | static async generateApiKey({ user_id = null, name = '' } = {}) { |
| 3383 | try { |
| 3384 | const body = {}; |
| 3385 | if (user_id) body.user_id = user_id; |
| 3386 | if (name) body.name = name; |
| 3387 | |
| 3388 | const response = await request( |
| 3389 | `${host}/api/accounts/api-keys/generate/`, |
| 3390 | { |
| 3391 | method: 'POST', |
| 3392 | body, |
| 3393 | } |
| 3394 | ); |
| 3395 | |
| 3396 | // If the backend returned an updated user, refresh the users store |
| 3397 | try { |
| 3398 | if (response && response.user) { |
| 3399 | useUsersStore.getState().updateUser(response.user); |
| 3400 | } |
| 3401 | } catch (e) { |
| 3402 | // ignore store update errors |
| 3403 | } |
| 3404 | |
| 3405 | return response; |
| 3406 | } catch (e) { |
| 3407 | errorNotification('Failed to generate API key', e); |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | static async revokeApiKey({ user_id = null } = {}) { |
| 3412 | try { |
no test coverage detected