mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 15:33:57 +00:00
admin login support
This commit is contained in:
@@ -7,9 +7,13 @@
|
|||||||
import FormSubmit from './forms/FormSubmit.svelte';
|
import FormSubmit from './forms/FormSubmit.svelte';
|
||||||
import FormTextField from './forms/FormTextField.svelte';
|
import FormTextField from './forms/FormTextField.svelte';
|
||||||
import { apiCall, enableApi } from './utility/api';
|
import { apiCall, enableApi } from './utility/api';
|
||||||
|
import { useConfig } from './utility/metadataLoaders';
|
||||||
|
import ErrorInfo from './elements/ErrorInfo.svelte';
|
||||||
|
|
||||||
export let isAdminPage;
|
export let isAdminPage;
|
||||||
|
|
||||||
|
const config = useConfig();
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const removed = document.getElementById('starting_dbgate_zero');
|
const removed = document.getElementById('starting_dbgate_zero');
|
||||||
if (removed) removed.remove();
|
if (removed) removed.remove();
|
||||||
@@ -30,6 +34,10 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<FormPasswordField label="Password" name="password" autocomplete="current-password" saveOnInput />
|
<FormPasswordField label="Password" name="password" autocomplete="current-password" saveOnInput />
|
||||||
|
|
||||||
|
{#if isAdminPage && $config && !$config.isAdminLoginForm}
|
||||||
|
<ErrorInfo message="Admin login is not configured. Please set ADMIN_PASSWORD environment variable" />
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="submit">
|
<div class="submit">
|
||||||
<FormSubmit
|
<FormSubmit
|
||||||
value={isAdminPage ? 'Log In as Administrator' : 'Log In'}
|
value={isAdminPage ? 'Log In as Administrator' : 'Log In'}
|
||||||
@@ -40,13 +48,19 @@
|
|||||||
...e.detail,
|
...e.detail,
|
||||||
});
|
});
|
||||||
if (resp.error) {
|
if (resp.error) {
|
||||||
internalRedirectTo(`/?page=not-logged&error=${encodeURIComponent(resp.error)}`);
|
internalRedirectTo(
|
||||||
|
`/?page=not-logged&error=${encodeURIComponent(resp.error)}&is-admin=${isAdminPage ? 'true' : ''}`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { accessToken } = resp;
|
const { accessToken } = resp;
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
localStorage.setItem('accessToken', accessToken);
|
localStorage.setItem('accessToken', accessToken);
|
||||||
|
if (isAdminPage) {
|
||||||
|
internalRedirectTo('/?page=admin');
|
||||||
|
} else {
|
||||||
internalRedirectTo('/');
|
internalRedirectTo('/');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
internalRedirectTo(`/?page=not-logged`);
|
internalRedirectTo(`/?page=not-logged`);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import FormStyledButton from './buttons/FormStyledButton.svelte';
|
import FormStyledButton from './buttons/FormStyledButton.svelte';
|
||||||
import { doLogout, redirectToLogin } from './clientAuth';
|
import { doLogout, redirectToAdminLogin, redirectToLogin } from './clientAuth';
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const removed = document.getElementById('starting_dbgate_zero');
|
const removed = document.getElementById('starting_dbgate_zero');
|
||||||
@@ -10,10 +10,15 @@
|
|||||||
|
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
const error = params.get('error');
|
const error = params.get('error');
|
||||||
|
const isAdmin = params.get('is-admin') == 'true';
|
||||||
|
|
||||||
function handleLogin() {
|
function handleLogin() {
|
||||||
|
if (isAdmin) {
|
||||||
|
redirectToAdminLogin();
|
||||||
|
} else {
|
||||||
redirectToLogin(undefined, true);
|
redirectToLogin(undefined, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="root theme-light theme-type-light">
|
<div class="root theme-light theme-type-light">
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export function handleOauthCallback() {
|
|||||||
|
|
||||||
export async function handleAuthOnStartup(config, isAdminPage = false) {
|
export async function handleAuthOnStartup(config, isAdminPage = false) {
|
||||||
if (config.isAdminLoginForm && isAdminPage) {
|
if (config.isAdminLoginForm && isAdminPage) {
|
||||||
if (localStorage.getItem('adminAccessToken')) {
|
if (localStorage.getItem('accessToken')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user