Implement new admin get self endpoint, move auth store to the portal, and implement working password changing and name changing
This commit is contained in:
parent
4824d7810a
commit
5de98bb672
|
@ -7,8 +7,7 @@
|
||||||
Body,
|
Body,
|
||||||
Heading,
|
Heading,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { organisation } from "stores/portal"
|
import { organisation, auth } from "stores/portal"
|
||||||
import { auth } from "stores/backend"
|
|
||||||
|
|
||||||
let email = ""
|
let email = ""
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
Heading,
|
Heading,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import GoogleButton from "./GoogleButton.svelte"
|
import GoogleButton from "./GoogleButton.svelte"
|
||||||
import { auth } from "stores/backend"
|
import { organisation, auth } from "stores/portal"
|
||||||
import { organisation } from "stores/portal"
|
|
||||||
|
|
||||||
let username = ""
|
let username = ""
|
||||||
let password = ""
|
let password = ""
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
<script>
|
<script>
|
||||||
import { notifications, Button, Layout, Body, Heading } from "@budibase/bbui"
|
import { notifications, Button, Layout, Body, Heading } from "@budibase/bbui"
|
||||||
import { organisation } from "stores/portal"
|
import { organisation, auth } from "stores/portal"
|
||||||
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
|
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
|
||||||
import { params, goto } from "@roxi/routify"
|
import { params, goto } from "@roxi/routify"
|
||||||
import { auth } from "stores/backend"
|
|
||||||
|
|
||||||
const resetCode = $params["?code"]
|
const resetCode = $params["?code"]
|
||||||
let password, error
|
let password, error
|
||||||
|
|
|
@ -6,12 +6,9 @@
|
||||||
Layout,
|
Layout,
|
||||||
ActionMenu,
|
ActionMenu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
Link,
|
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { gradient } from "actions"
|
import { gradient } from "actions"
|
||||||
import { AppStatus } from "constants"
|
import { auth } from "stores/portal"
|
||||||
import { url } from "@roxi/routify"
|
|
||||||
import { auth } from "stores/backend"
|
|
||||||
|
|
||||||
export let app
|
export let app
|
||||||
export let exportApp
|
export let exportApp
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { gradient } from "actions"
|
import { gradient } from "actions"
|
||||||
import { Heading, Button, Icon, ActionMenu, MenuItem } from "@budibase/bbui"
|
import { Heading, Button, Icon, ActionMenu, MenuItem } from "@budibase/bbui"
|
||||||
import { auth } from "stores/backend"
|
import { auth } from "stores/portal"
|
||||||
|
|
||||||
export let app
|
export let app
|
||||||
export let openApp
|
export let openApp
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { isActive, redirect } from "@roxi/routify"
|
import { isActive, redirect } from "@roxi/routify"
|
||||||
import { auth } from "stores/backend"
|
import { admin, auth } from "stores/portal"
|
||||||
import { admin } from "stores/portal"
|
|
||||||
|
|
||||||
let loaded = false
|
let loaded = false
|
||||||
$: hasAdminUser = !!$admin?.checklist?.adminUser
|
$: hasAdminUser = !!$admin?.checklist?.adminUser
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { auth } from "stores/backend"
|
import { auth } from "stores/portal"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $auth.user}
|
{#if $auth.user}
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
<script>
|
<script>
|
||||||
import { ModalContent, Body, notifications } from "@budibase/bbui"
|
import { ModalContent, Body, notifications } from "@budibase/bbui"
|
||||||
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
|
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
|
||||||
|
import { auth } from "stores/portal"
|
||||||
|
|
||||||
let password
|
let password
|
||||||
let error
|
let error
|
||||||
|
|
||||||
const updatePassword = async () => {
|
const updatePassword = async () => {
|
||||||
// Update password
|
try {
|
||||||
|
await auth.updateSelf({ ...$auth.user, password })
|
||||||
|
notifications.success("Information updated successfully")
|
||||||
|
} catch (error) {
|
||||||
|
notifications.error("Failed to update password")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -14,7 +20,7 @@
|
||||||
title="Change password"
|
title="Change password"
|
||||||
confirmText="Update password"
|
confirmText="Update password"
|
||||||
onConfirm={updatePassword}
|
onConfirm={updatePassword}
|
||||||
disabled={error}
|
disabled={error || !password}
|
||||||
>
|
>
|
||||||
<Body size="S">Enter your new password below.</Body>
|
<Body size="S">Enter your new password below.</Body>
|
||||||
<PasswordRepeatInput bind:password bind:error />
|
<PasswordRepeatInput bind:password bind:error />
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { ModalContent, Body, Input } from "@budibase/bbui"
|
import { ModalContent, Body, Input, notifications } from "@budibase/bbui"
|
||||||
import { writable } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
import { auth } from "stores/backend"
|
import { auth } from "stores/portal"
|
||||||
|
|
||||||
const values = writable({
|
const values = writable({
|
||||||
firstName: $auth.user.firstName,
|
firstName: $auth.user.firstName,
|
||||||
|
@ -9,7 +9,12 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateInfo = async () => {
|
const updateInfo = async () => {
|
||||||
// Update name
|
try {
|
||||||
|
await auth.updateSelf({ ...$auth.user, ...$values })
|
||||||
|
notifications.success("Information updated successfully")
|
||||||
|
} catch (error) {
|
||||||
|
notifications.error("Failed to update information")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { auth } from "stores/backend"
|
import { auth } from "stores/portal"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $auth.user}
|
{#if $auth.user}
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
Modal,
|
Modal,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { apps, organisation } from "stores/portal"
|
import { apps, organisation, auth } from "stores/portal"
|
||||||
import { auth } from "stores/backend"
|
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import { AppStatus } from "constants"
|
import { AppStatus } from "constants"
|
||||||
import { gradient } from "actions"
|
import { gradient } from "actions"
|
||||||
|
@ -73,36 +72,45 @@
|
||||||
</ActionMenu>
|
</ActionMenu>
|
||||||
</div>
|
</div>
|
||||||
<Divider />
|
<Divider />
|
||||||
<div class="apps-title">
|
{#if $apps.length}
|
||||||
<Heading>Apps</Heading>
|
<div class="apps-title">
|
||||||
<Select placeholder="Filter by groups" />
|
<Heading>Apps</Heading>
|
||||||
</div>
|
<Select placeholder="Filter by groups" />
|
||||||
<div class="group">
|
</div>
|
||||||
<Layout gap="S" noPadding>
|
<div class="group">
|
||||||
<div class="group-title">
|
<Layout gap="S" noPadding>
|
||||||
<Body weight="500" size="XS">GROUP</Body>
|
<div class="group-title">
|
||||||
{#if $auth.user?.builder?.global}
|
<Body weight="500" size="XS">GROUP</Body>
|
||||||
<Icon
|
{#if $auth.user?.builder?.global}
|
||||||
name="Settings"
|
<Icon
|
||||||
hoverable
|
name="Settings"
|
||||||
on:click={() => alert("Navigate to portal group page.")}
|
hoverable
|
||||||
/>
|
on:click={() => alert("Navigate to portal group page.")}
|
||||||
{/if}
|
/>
|
||||||
</div>
|
{/if}
|
||||||
{#each $apps as app, idx (app.appId)}
|
</div>
|
||||||
<a class="app" target="_blank" href={`/${app.appId}`}>
|
{#each $apps as app, idx (app.appId)}
|
||||||
<div class="preview" use:gradient={{ seed: app.name }} />
|
<a class="app" target="_blank" href={`/${app.appId}`}>
|
||||||
<div class="app-info">
|
<div class="preview" use:gradient={{ seed: app.name }} />
|
||||||
<Heading size="XS">{app.name}</Heading>
|
<div class="app-info">
|
||||||
<Body size="S">
|
<Heading size="XS">{app.name}</Heading>
|
||||||
Edited {Math.round(Math.random() * 10 + 1)} months ago
|
<Body size="S">
|
||||||
</Body>
|
Edited {Math.round(Math.random() * 10 + 1)} months ago
|
||||||
</div>
|
</Body>
|
||||||
<Icon name="ChevronRight" />
|
</div>
|
||||||
</a>
|
<Icon name="ChevronRight" />
|
||||||
{/each}
|
</a>
|
||||||
|
{/each}
|
||||||
|
</Layout>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<Layout gap="XS" noPadding>
|
||||||
|
<Heading size="S">You don't have access to any apps yet.</Heading>
|
||||||
|
<Body size="S"
|
||||||
|
>The apps you have access to will be listed here.</Body
|
||||||
|
>
|
||||||
</Layout>
|
</Layout>
|
||||||
</div>
|
{/if}
|
||||||
</Layout>
|
</Layout>
|
||||||
</div>
|
</div>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { redirect } from "@roxi/routify"
|
import { redirect } from "@roxi/routify"
|
||||||
import { auth } from "stores/backend"
|
import { auth } from "stores/portal"
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (!$auth.user) {
|
if (!$auth.user) {
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
Modal,
|
Modal,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import ConfigChecklist from "components/common/ConfigChecklist.svelte"
|
import ConfigChecklist from "components/common/ConfigChecklist.svelte"
|
||||||
import { organisation } from "stores/portal"
|
import { organisation, auth } from "stores/portal"
|
||||||
import { auth } from "stores/backend"
|
|
||||||
import BuilderSettingsModal from "components/start/BuilderSettingsModal.svelte"
|
import BuilderSettingsModal from "components/start/BuilderSettingsModal.svelte"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
import api, { del } from "builderStore/api"
|
import api, { del } from "builderStore/api"
|
||||||
import analytics from "analytics"
|
import analytics from "analytics"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { apps } from "stores/portal"
|
import { apps, auth } from "stores/portal"
|
||||||
import { auth } from "stores/backend"
|
|
||||||
import download from "downloadjs"
|
import download from "downloadjs"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
|
|
|
@ -7,4 +7,3 @@ export { roles } from "./roles"
|
||||||
export { datasources } from "./datasources"
|
export { datasources } from "./datasources"
|
||||||
export { integrations } from "./integrations"
|
export { integrations } from "./integrations"
|
||||||
export { queries } from "./queries"
|
export { queries } from "./queries"
|
||||||
export { auth } from "./auth"
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ export function createAuthStore() {
|
||||||
return {
|
return {
|
||||||
subscribe: store.subscribe,
|
subscribe: store.subscribe,
|
||||||
checkAuth: async () => {
|
checkAuth: async () => {
|
||||||
const response = await api.get("/api/self")
|
const response = await api.get("/api/admin/users/self")
|
||||||
const user = await response.json()
|
const user = await response.json()
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
store.update(state => ({ ...state, user }))
|
store.update(state => ({ ...state, user }))
|
||||||
|
@ -33,6 +33,14 @@ export function createAuthStore() {
|
||||||
await response.json()
|
await response.json()
|
||||||
store.update(state => ({ ...state, user: null }))
|
store.update(state => ({ ...state, user: null }))
|
||||||
},
|
},
|
||||||
|
updateSelf: async user => {
|
||||||
|
const response = await api.post("/api/admin/users/self", user)
|
||||||
|
if (response.status === 200) {
|
||||||
|
store.update(state => ({ ...state, user: { ...state.user, ...user } }))
|
||||||
|
} else {
|
||||||
|
throw "Unable to update user details"
|
||||||
|
}
|
||||||
|
},
|
||||||
forgotPassword: async email => {
|
forgotPassword: async email => {
|
||||||
const response = await api.post(`/api/admin/auth/reset`, {
|
const response = await api.post(`/api/admin/auth/reset`, {
|
||||||
email,
|
email,
|
|
@ -3,3 +3,4 @@ export { users } from "./users"
|
||||||
export { admin } from "./admin"
|
export { admin } from "./admin"
|
||||||
export { apps } from "./apps"
|
export { apps } from "./apps"
|
||||||
export { email } from "./email"
|
export { email } from "./email"
|
||||||
|
export { auth } from "./auth"
|
||||||
|
|
Loading…
Reference in New Issue