mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-22 00:01:34 +00:00
203f6785c4
Split SvelteKit-specific code into separate files to allow windmill-components to be used as a library in non-SvelteKit contexts (e.g., windmill-react-sdk): - Split logout.ts into logout.ts and logoutKit.ts - Split svelte5Utils.svelte.ts into svelte5Utils.svelte.ts and svelte5UtilsKit.svelte.ts (for runed/kit useSearchParams) - Fix triggers/utils.ts type-only import resolution - Update FlowRestartButton to use callback instead of direct navigation - Update all route files to import from logoutKit Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
29 lines
1018 B
TypeScript
29 lines
1018 B
TypeScript
// SvelteKit-specific logout utilities
|
|
// These functions depend on $lib/navigation which requires SvelteKit
|
|
|
|
import { goto } from '$lib/navigation'
|
|
import { clearUser } from './logout'
|
|
import { sendUserToast } from './toast'
|
|
|
|
export async function logoutWithRedirect(rd?: string): Promise<void> {
|
|
console.log('logoutWithRedirect', rd)
|
|
await clearUser()
|
|
const splitted = rd?.split('?')[0]
|
|
if (rd && rd != '/' && splitted != '/user/login' && splitted != '/user/logout') {
|
|
const error = document.cookie.includes('token')
|
|
? `error=${encodeURIComponent('You have been logged out because your session has expired.')}&`
|
|
: ''
|
|
console.log('login redirect with error', error, rd)
|
|
goto(`/user/login?${error}${rd ? 'rd=' + encodeURIComponent(rd) : ''}`, { replaceState: true })
|
|
} else {
|
|
console.log('login redirect vanilla')
|
|
goto('/user/login', { replaceState: true })
|
|
}
|
|
}
|
|
|
|
export async function logout(): Promise<void> {
|
|
await clearUser()
|
|
goto(`/user/login`)
|
|
sendUserToast('you have been logged out')
|
|
}
|