Browse Source

Fixes for review comments.

pull/4732/head
mike12345567 5 years ago
parent
commit
c5c10cbc79
  1. 8
      packages/builder/src/components/settings/UpdateAPIKeyModal.svelte
  2. 2
      packages/builder/src/pages/builder/portal/_layout.svelte
  3. 5
      packages/builder/src/stores/portal/auth.js
  4. 36
      packages/frontend-core/src/api/self.js
  5. 31
      packages/frontend-core/src/api/user.js

8
packages/builder/src/components/settings/UpdateAPIKeyModal.svelte

@ -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>

2
packages/builder/src/pages/builder/portal/_layout.svelte

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

5
packages/builder/src/stores/portal/auth.js

@ -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
},
}

36
packages/frontend-core/src/api/self.js

@ -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,
})
},
})

31
packages/frontend-core/src/api/user.js

@ -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

Loading…
Cancel
Save