mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 00:16:00 +00:00
logout button from not logged page
This commit is contained in:
@@ -69,11 +69,13 @@ module.exports = {
|
|||||||
|
|
||||||
const payload = jwt.decode(access_token);
|
const payload = jwt.decode(access_token);
|
||||||
|
|
||||||
|
console.log('User payload returned from OAUTH:', payload);
|
||||||
|
|
||||||
const login = process.env.OAUTH_LOGIN_FIELD ? payload[process.env.OAUTH_LOGIN_FIELD] : 'oauth';
|
const login = process.env.OAUTH_LOGIN_FIELD ? payload[process.env.OAUTH_LOGIN_FIELD] : 'oauth';
|
||||||
|
|
||||||
if (
|
if (
|
||||||
process.env.OAUTH_ALLOWED_LOGINS &&
|
process.env.OAUTH_ALLOWED_LOGINS &&
|
||||||
!process.env.OAUTH_ALLOWED_LOGINS.split(',').find(x => x.toLowerCase().trim() != login.toLowerCase().trim())
|
!process.env.OAUTH_ALLOWED_LOGINS.split(',').find(x => x.toLowerCase().trim() == login.toLowerCase().trim())
|
||||||
) {
|
) {
|
||||||
return { error: `Username ${login} not allowed to log in` };
|
return { error: `Username ${login} not allowed to log in` };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 { redirectToLogin } from './clientAuth';
|
import { doLogout, redirectToLogin } from './clientAuth';
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const removed = document.getElementById('starting_dbgate_zero');
|
const removed = document.getElementById('starting_dbgate_zero');
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
<div class="button">
|
<div class="button">
|
||||||
<FormStyledButton value="Log In" on:click={handleLogin} />
|
<FormStyledButton value="Log In" on:click={handleLogin} />
|
||||||
|
<FormStyledButton value="Log Out" on:click={doLogout} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { apiCall, disableApi, enableApi } from './utility/api';
|
import { apiCall, enableApi } from './utility/api';
|
||||||
import { getConfig } from './utility/metadataLoaders';
|
import { getConfig } from './utility/metadataLoaders';
|
||||||
|
|
||||||
export function isOauthCallback() {
|
export function isOauthCallback() {
|
||||||
@@ -40,6 +40,9 @@ export function handleOauthCallback() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function handleAuthOnStartup(config) {
|
export async function handleAuthOnStartup(config) {
|
||||||
|
if (config.oauth) {
|
||||||
|
console.log('OAUTH callback URL:', location.origin + location.pathname);
|
||||||
|
}
|
||||||
if (config.oauth || config.isLoginForm) {
|
if (config.oauth || config.isLoginForm) {
|
||||||
if (localStorage.getItem('accessToken')) {
|
if (localStorage.getItem('accessToken')) {
|
||||||
return;
|
return;
|
||||||
@@ -84,3 +87,21 @@ export function internalRedirectTo(path) {
|
|||||||
const newPath = index >= 0 ? location.pathname.substring(0, index) + path : path;
|
const newPath = index >= 0 ? location.pathname.substring(0, index) + path : path;
|
||||||
location.replace(newPath);
|
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 { openWebLink } from '../utility/exportFileTools';
|
||||||
import { getSettings } from '../utility/metadataLoaders';
|
import { getSettings } from '../utility/metadataLoaders';
|
||||||
import { isMac } from '../utility/common';
|
import { isMac } from '../utility/common';
|
||||||
import { internalRedirectTo } from '../clientAuth';
|
import { doLogout, internalRedirectTo } from '../clientAuth';
|
||||||
|
|
||||||
// function themeCommand(theme: ThemeDefinition) {
|
// function themeCommand(theme: ThemeDefinition) {
|
||||||
// return {
|
// return {
|
||||||
@@ -549,22 +549,7 @@ registerCommand({
|
|||||||
category: 'App',
|
category: 'App',
|
||||||
name: 'Logout',
|
name: 'Logout',
|
||||||
testEnabled: () => getCurrentConfig()?.login != null,
|
testEnabled: () => getCurrentConfig()?.login != null,
|
||||||
onClick: () => {
|
onClick: doLogout,
|
||||||
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';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export function registerFileCommands({
|
export function registerFileCommands({
|
||||||
|
|||||||
Reference in New Issue
Block a user