logout button from not logged page

This commit is contained in:
Jan Prochazka
2022-11-27 10:56:50 +01:00
parent d84adcca5d
commit 012d3ec2e1
4 changed files with 29 additions and 20 deletions

View File

@@ -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';
}
}