|
| 1 | +import { DynamicTheme } from "@/components/dynamic-theme"; |
| 2 | +import { SessionsClearList } from "@/components/sessions-clear-list"; |
| 3 | +import { getAllSessionCookieIds } from "@/lib/cookies"; |
| 4 | +import { getServiceUrlFromHeaders } from "@/lib/service-url"; |
| 5 | +import { |
| 6 | + getBrandingSettings, |
| 7 | + getDefaultOrg, |
| 8 | + listSessions, |
| 9 | +} from "@/lib/zitadel"; |
| 10 | +import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb"; |
| 11 | +import { getLocale, getTranslations } from "next-intl/server"; |
| 12 | +import { headers } from "next/headers"; |
| 13 | + |
| 14 | +async function loadSessions({ serviceUrl }: { serviceUrl: string }) { |
| 15 | + const ids: (string | undefined)[] = await getAllSessionCookieIds(); |
| 16 | + |
| 17 | + if (ids && ids.length) { |
| 18 | + const response = await listSessions({ |
| 19 | + serviceUrl, |
| 20 | + ids: ids.filter((id) => !!id) as string[], |
| 21 | + }); |
| 22 | + return response?.sessions ?? []; |
| 23 | + } else { |
| 24 | + console.info("No session cookie found."); |
| 25 | + return []; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +export default async function Page(props: { |
| 30 | + searchParams: Promise<Record<string | number | symbol, string | undefined>>; |
| 31 | +}) { |
| 32 | + const searchParams = await props.searchParams; |
| 33 | + const locale = getLocale(); |
| 34 | + const t = await getTranslations({ locale, namespace: "logout" }); |
| 35 | + |
| 36 | + const organization = searchParams?.organization; |
| 37 | + const postLogoutRedirectUri = searchParams?.post_logout_redirect_uri; |
| 38 | + const logoutHint = searchParams?.logout_hint; |
| 39 | + const UILocales = searchParams?.ui_locales; // TODO implement with new translation service |
| 40 | + |
| 41 | + const _headers = await headers(); |
| 42 | + const { serviceUrl } = getServiceUrlFromHeaders(_headers); |
| 43 | + |
| 44 | + let defaultOrganization; |
| 45 | + if (!organization) { |
| 46 | + const org: Organization | null = await getDefaultOrg({ |
| 47 | + serviceUrl, |
| 48 | + }); |
| 49 | + if (org) { |
| 50 | + defaultOrganization = org.id; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + let sessions = await loadSessions({ serviceUrl }); |
| 55 | + |
| 56 | + const branding = await getBrandingSettings({ |
| 57 | + serviceUrl, |
| 58 | + organization: organization ?? defaultOrganization, |
| 59 | + }); |
| 60 | + |
| 61 | + const params = new URLSearchParams(); |
| 62 | + |
| 63 | + if (organization) { |
| 64 | + params.append("organization", organization); |
| 65 | + } |
| 66 | + |
| 67 | + return ( |
| 68 | + <DynamicTheme branding={branding}> |
| 69 | + <div className="flex flex-col items-center space-y-4"> |
| 70 | + <h1>{t("title")}</h1> |
| 71 | + <p className="ztdl-p mb-6 block">{t("description")}</p> |
| 72 | + |
| 73 | + <div className="flex flex-col w-full space-y-2"> |
| 74 | + <SessionsClearList |
| 75 | + sessions={sessions} |
| 76 | + logoutHint={logoutHint} |
| 77 | + postLogoutRedirectUri={postLogoutRedirectUri} |
| 78 | + organization={organization ?? defaultOrganization} |
| 79 | + /> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + </DynamicTheme> |
| 83 | + ); |
| 84 | +} |
0 commit comments