forked from tsai/budibase
9 changed files with 202 additions and 22 deletions
@ -0,0 +1,47 @@ |
|||
import { writable } from "svelte/store" |
|||
import api, { get } from "../api" |
|||
|
|||
const INITIAL_ADMIN_STATE = { |
|||
oauth: [] |
|||
} |
|||
|
|||
export const getAdminStore = () => { |
|||
const store = writable({ ...INITIAL_ADMIN_STATE }) |
|||
store.actions = { |
|||
fetch: async () => { |
|||
const responses = await Promise.all([ |
|||
api.get("/api/hosting/"), |
|||
api.get("/api/hosting/urls"), |
|||
]) |
|||
const [info, urls] = await Promise.all(responses.map(resp => resp.json())) |
|||
store.update(state => { |
|||
state.hostingInfo = info |
|||
state.appUrl = urls.app |
|||
return state |
|||
}) |
|||
return info |
|||
}, |
|||
save: async hostingInfo => { |
|||
const response = await api.post("/api/hosting", hostingInfo) |
|||
const revision = (await response.json()).rev |
|||
store.update(state => { |
|||
state.hostingInfo = { |
|||
...hostingInfo, |
|||
_rev: revision, |
|||
} |
|||
return state |
|||
}) |
|||
}, |
|||
fetchDeployedApps: async () => { |
|||
let deployments = await (await get("/api/hosting/apps")).json() |
|||
store.update(state => { |
|||
state.deployedApps = deployments |
|||
state.deployedAppNames = Object.values(deployments).map(app => app.name) |
|||
state.deployedAppUrls = Object.values(deployments).map(app => app.url) |
|||
return state |
|||
}) |
|||
return deployments |
|||
}, |
|||
} |
|||
return store |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<script> |
|||
import { hostingStore } from "builderStore" |
|||
import { HostingTypes } from "constants/backend" |
|||
import GoogleLogo from "./logos/Google.svelte" |
|||
import { |
|||
Button, |
|||
Heading, |
|||
Divider, |
|||
notifications, |
|||
Input, |
|||
ModalContent, |
|||
Toggle, |
|||
Body, |
|||
} from "@budibase/bbui" |
|||
import ThemeEditor from "components/settings/ThemeEditor.svelte" |
|||
import analytics from "analytics" |
|||
import { onMount } from "svelte" |
|||
import api from "builderStore/api" |
|||
|
|||
const ConfigTypes = { |
|||
Google: "google", |
|||
// Github: "github", |
|||
// AzureAD: "ad", |
|||
} |
|||
|
|||
const ConfigFields = { |
|||
Google: ["clientID", "clientSecret", "callbackURL"], |
|||
} |
|||
|
|||
let google |
|||
|
|||
async function save(doc) { |
|||
try { |
|||
// Save an oauth config |
|||
const response = await api.post(`/api/admin/configs`, doc) |
|||
const json = await response.json() |
|||
if (response.status !== 200) throw new Error(json.message) |
|||
|
|||
google._rev = json._rev |
|||
google._id = json._id |
|||
notifications.success(`Settings saved.`) |
|||
} catch (err) { |
|||
notifications.error(`Failed to update OAuth settings. ${err}`) |
|||
} |
|||
} |
|||
|
|||
onMount(async () => { |
|||
// fetch the configs for oauth |
|||
const googleResponse = await api.get( |
|||
`/api/admin/configs/${ConfigTypes.Google}` |
|||
) |
|||
const googleDoc = await googleResponse.json() |
|||
|
|||
if (!googleDoc._id) { |
|||
google = { |
|||
type: "google", |
|||
config: {}, |
|||
} |
|||
} else { |
|||
google = googleDoc |
|||
} |
|||
}) |
|||
</script> |
|||
|
|||
<section class="container"> |
|||
<Heading size="M">OAuth</Heading> |
|||
<Body size="S"> |
|||
Every budibase app comes with basic authentication (email/password) |
|||
included. You can add additional authentication methods from the options |
|||
below. |
|||
</Body> |
|||
<Divider /> |
|||
{#if google} |
|||
<div class="form"> |
|||
<Heading size="S"> |
|||
<GoogleLogo /> |
|||
Google |
|||
</Heading> |
|||
{#each ConfigFields.Google as field} |
|||
<Input bind:value={google.config[field]} label={field} /> |
|||
{/each} |
|||
<Button primary on:click={() => save(google)}>Save</Button> |
|||
</div> |
|||
{/if} |
|||
</section> |
|||
|
|||
<style> |
|||
section { |
|||
margin: 40px 80px; |
|||
} |
|||
</style> |
|||
|
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in new issue