1
0
Fork 0
mirror of synced 2024-06-14 08:24:48 +12:00

Fixes for review comments.

This commit is contained in:
mike12345567 2022-02-28 18:39:05 +00:00
parent 6415abb3d4
commit c5c10cbc79
5 changed files with 43 additions and 39 deletions

View file

@ -9,7 +9,7 @@
async function generateAPIKey() {
try {
apiKey = await auth.generateAPIKey()
notifications.success("New API key generated.")
notifications.success("New API key generated")
} catch (err) {
notifications.error("Unable to generate new API key")
}
@ -18,7 +18,11 @@
}
onMount(async () => {
apiKey = await auth.fetchAPIKey()
try {
apiKey = await auth.fetchAPIKey()
} catch (err) {
notifications.error("Unable to fetch API key")
}
})
</script>

View file

@ -166,7 +166,7 @@
</MenuItem>
{#if $auth.isBuilder}
<MenuItem icon="Key" on:click={() => apiKeyModal.show()}>
View developer information
View API key
</MenuItem>
{/if}
<MenuItem

View file

@ -173,12 +173,11 @@ export function createAuthStore() {
})
},
generateAPIKey: async () => {
const info = await API.generateAPIKey()
return info?.apiKey ? info.apiKey : null
return API.generateAPIKey()
},
fetchAPIKey: async () => {
const info = await API.fetchDeveloperInfo()
return info?.apiKey ? info.apiKey : null
return info?.apiKey
},
}

View file

@ -5,9 +5,10 @@ export const buildSelfEndpoints = API => ({
* @return {Promise<object>} returns the API response, including an API key.
*/
generateAPIKey: async () => {
return await API.post({
const response = await API.post({
url: "/api/global/self/api_key",
})
return response?.apiKey
},
/**
@ -15,8 +16,39 @@ export const buildSelfEndpoints = API => ({
* @return {Promise<object>} An object containing the user developer information.
*/
fetchDeveloperInfo: async () => {
return await API.get({
return API.get({
url: "/api/global/self/api_key",
})
},
/**
* Fetches the currently logged-in user object.
* Used in client apps.
*/
fetchSelf: async () => {
return await API.get({
url: "/api/self",
})
},
/**
* Fetches the currently logged-in user object.
* Used in the builder.
*/
fetchBuilderSelf: async () => {
return await API.get({
url: "/api/global/self",
})
},
/**
* Updates the current logged-in user.
* @param user the new user object to save
*/
updateSelf: async user => {
return await API.post({
url: "/api/global/self",
body: user,
})
},
})

View file

@ -1,24 +1,4 @@
export const buildUserEndpoints = API => ({
/**
* Fetches the currently logged-in user object.
* Used in client apps.
*/
fetchSelf: async () => {
return await API.get({
url: "/api/self",
})
},
/**
* Fetches the currently logged-in user object.
* Used in the builder.
*/
fetchBuilderSelf: async () => {
return await API.get({
url: "/api/global/self",
})
},
/**
* Gets a list of users in the current tenant.
*/
@ -61,17 +41,6 @@ export const buildUserEndpoints = API => ({
})
},
/**
* Updates the current logged-in user.
* @param user the new user object to save
*/
updateSelf: async user => {
return await API.post({
url: "/api/global/self",
body: user,
})
},
/**
* Creates or updates a user in the current tenant.
* @param user the new user to create