mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 05:26:00 +00:00
logout button from not logged page
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import FormStyledButton from './buttons/FormStyledButton.svelte';
|
||||
import { redirectToLogin } from './clientAuth';
|
||||
import { doLogout, redirectToLogin } from './clientAuth';
|
||||
|
||||
onMount(() => {
|
||||
const removed = document.getElementById('starting_dbgate_zero');
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
<div class="button">
|
||||
<FormStyledButton value="Log In" on:click={handleLogin} />
|
||||
<FormStyledButton value="Log Out" on:click={doLogout} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { apiCall, disableApi, enableApi } from './utility/api';
|
||||
import { apiCall, enableApi } from './utility/api';
|
||||
import { getConfig } from './utility/metadataLoaders';
|
||||
|
||||
export function isOauthCallback() {
|
||||
@@ -40,6 +40,9 @@ export function handleOauthCallback() {
|
||||
}
|
||||
|
||||
export async function handleAuthOnStartup(config) {
|
||||
if (config.oauth) {
|
||||
console.log('OAUTH callback URL:', location.origin + location.pathname);
|
||||
}
|
||||
if (config.oauth || config.isLoginForm) {
|
||||
if (localStorage.getItem('accessToken')) {
|
||||
return;
|
||||
@@ -84,3 +87,21 @@ export function internalRedirectTo(path) {
|
||||
const newPath = index >= 0 ? location.pathname.substring(0, index) + path : path;
|
||||
location.replace(newPath);
|
||||
}
|
||||
|
||||
export async function doLogout() {
|
||||
enableApi();
|
||||
const config = await getConfig();
|
||||
if (config.oauth) {
|
||||
localStorage.removeItem('accessToken');
|
||||
if (config.oauthLogout) {
|
||||
window.location.href = config.oauthLogout;
|
||||
} else {
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
}
|
||||
} else if (config.isLoginForm) {
|
||||
localStorage.removeItem('accessToken');
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
} else {
|
||||
window.location.href = 'config/logout';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import runCommand from './runCommand';
|
||||
import { openWebLink } from '../utility/exportFileTools';
|
||||
import { getSettings } from '../utility/metadataLoaders';
|
||||
import { isMac } from '../utility/common';
|
||||
import { internalRedirectTo } from '../clientAuth';
|
||||
import { doLogout, internalRedirectTo } from '../clientAuth';
|
||||
|
||||
// function themeCommand(theme: ThemeDefinition) {
|
||||
// return {
|
||||
@@ -549,22 +549,7 @@ registerCommand({
|
||||
category: 'App',
|
||||
name: 'Logout',
|
||||
testEnabled: () => getCurrentConfig()?.login != null,
|
||||
onClick: () => {
|
||||
const config = getCurrentConfig();
|
||||
if (config.oauth) {
|
||||
localStorage.removeItem('accessToken');
|
||||
if (config.oauthLogout) {
|
||||
window.location.href = config.oauthLogout;
|
||||
} else {
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
}
|
||||
} else if (config.isLoginForm) {
|
||||
localStorage.removeItem('accessToken');
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
} else {
|
||||
window.location.href = 'config/logout';
|
||||
}
|
||||
},
|
||||
onClick: doLogout,
|
||||
});
|
||||
|
||||
export function registerFileCommands({
|
||||
|
||||
Reference in New Issue
Block a user