mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-02 03:59:45 +02:00
refac
This commit is contained in:
@@ -407,6 +407,36 @@ export const userSignOut = async () => {
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getLogoutRedirectUrl = (redirectUrl?: string | null) => {
|
||||
const logoutUrl = new URL('/auth?state=logout', window.location.origin);
|
||||
const postLogoutUrl = new URL('/auth', window.location.origin);
|
||||
if (!redirectUrl) {
|
||||
return logoutUrl.href;
|
||||
}
|
||||
|
||||
const url = new URL(redirectUrl, window.location.origin);
|
||||
if (url.origin === window.location.origin && url.pathname === '/auth') {
|
||||
url.searchParams.set('state', 'logout');
|
||||
return url.href;
|
||||
}
|
||||
|
||||
const postLogoutRedirectUri = url.searchParams.get('post_logout_redirect_uri');
|
||||
if (postLogoutRedirectUri) {
|
||||
const configuredPostLogoutUrl = new URL(postLogoutRedirectUri, window.location.origin);
|
||||
if (
|
||||
configuredPostLogoutUrl.origin === window.location.origin &&
|
||||
configuredPostLogoutUrl.pathname === '/auth'
|
||||
) {
|
||||
url.searchParams.set('state', 'logout');
|
||||
}
|
||||
return url.href;
|
||||
}
|
||||
|
||||
url.searchParams.set('post_logout_redirect_uri', postLogoutUrl.href);
|
||||
url.searchParams.set('state', 'logout');
|
||||
return url.href;
|
||||
};
|
||||
|
||||
export const addUser = async (
|
||||
token: string,
|
||||
name: string,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from 'svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { updateUserPassword, userSignOut } from '$lib/apis/auths';
|
||||
import { getLogoutRedirectUrl, updateUserPassword, userSignOut } from '$lib/apis/auths';
|
||||
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
@@ -32,7 +32,7 @@
|
||||
});
|
||||
|
||||
localStorage.removeItem('token');
|
||||
location.href = signOutRes?.redirect_url ?? '/auth?logout=true';
|
||||
location.href = getLogoutRedirectUrl(signOutRes?.redirect_url);
|
||||
}
|
||||
|
||||
currentPassword = '';
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import DOMPurify from 'dompurify';
|
||||
import { marked } from 'marked';
|
||||
|
||||
import { getAdminDetails, userSignOut } from '$lib/apis/auths';
|
||||
import { getAdminDetails, getLogoutRedirectUrl, userSignOut } from '$lib/apis/auths';
|
||||
import { onMount, tick, getContext } from 'svelte';
|
||||
import { config } from '$lib/stores';
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
return null;
|
||||
});
|
||||
localStorage.removeItem('token');
|
||||
location.href = res?.redirect_url ?? '/auth?logout=true';
|
||||
location.href = getLogoutRedirectUrl(res?.redirect_url);
|
||||
}}>{$i18n.t('Sign Out')}</button
|
||||
>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { fade, slide } from 'svelte/transition';
|
||||
|
||||
import { getUsage } from '$lib/apis';
|
||||
import { getSessionUser, userSignOut } from '$lib/apis/auths';
|
||||
import { getLogoutRedirectUrl, getSessionUser, userSignOut } from '$lib/apis/auths';
|
||||
|
||||
import { showSettings, mobile, showSidebar, user, config, settings } from '$lib/stores';
|
||||
|
||||
@@ -573,7 +573,7 @@
|
||||
const res = await userSignOut();
|
||||
localStorage.removeItem('token');
|
||||
|
||||
location.href = res?.redirect_url ?? '/auth?logout=true';
|
||||
location.href = getLogoutRedirectUrl(res?.redirect_url);
|
||||
show = false;
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -2884,6 +2884,7 @@
|
||||
"Upload Audio": "",
|
||||
"Upload directory": "",
|
||||
"Upload failed": "",
|
||||
"Upload failed for {{failed}} of {{total}} files.": "",
|
||||
"Upload files": "",
|
||||
"Upload Files": "",
|
||||
"Upload Model": "",
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
|
||||
onMount(async () => {
|
||||
const redirectPath = $page.url.searchParams.get('redirect');
|
||||
const logout = $page.url.searchParams.get('logout') === 'true';
|
||||
const logout = $page.url.searchParams.get('state') === 'logout';
|
||||
|
||||
if ($user && !logout) {
|
||||
goto(redirectPath || '/');
|
||||
@@ -175,7 +175,7 @@
|
||||
|
||||
// Auto-redirect to SSO when OAUTH_AUTO_REDIRECT is enabled and the
|
||||
// deployment is unambiguously SSO-only (single provider, no login form,
|
||||
// no LDAP). Suppressed by ?logout=true, ?form=, ?error=, onboarding,
|
||||
// no LDAP). Suppressed after logout, by ?form=, ?error=, onboarding,
|
||||
// trusted-header auth, or an existing session/token.
|
||||
if ($config?.oauth?.auto_redirect && !logout && !form && !error) {
|
||||
const providers = Object.keys($config?.oauth?.providers ?? {});
|
||||
|
||||
Reference in New Issue
Block a user