import { redirect } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { getWorkspaceLoginUrl } from '$lib/server/workspace-auth';

/**
 * KC redirects here after completing the logout flow.
 * This URL is covered by the app's registered wildcard in KC (e.g. anexo76-dev.aduanasoft.com/*).
 * We then send the user to workspace login so it can apply myApps() launcher logic.
 */
export const GET: RequestHandler = async ({ request, url }) => {
	const systemBaseUrl = url.origin;
	throw redirect(303, getWorkspaceLoginUrl(systemBaseUrl, { forPostLogout: true }));
};
