From e8fe9848fd83a58bcdc9d339111703f5829283e1 Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Fri, 25 Apr 2025 16:23:30 +0200 Subject: [PATCH 01/13] logout page --- apps/login/locales/de.json | 4 ++ apps/login/locales/en.json | 4 ++ apps/login/locales/es.json | 4 ++ apps/login/locales/it.json | 4 ++ apps/login/locales/pl.json | 4 ++ apps/login/locales/ru.json | 4 ++ apps/login/locales/zh.json | 4 ++ apps/login/src/app/(login)/logout/page.tsx | 81 ++++++++++++++++++++++ 8 files changed, 109 insertions(+) create mode 100644 apps/login/src/app/(login)/logout/page.tsx diff --git a/apps/login/locales/de.json b/apps/login/locales/de.json index db46321b05..171f6c705d 100644 --- a/apps/login/locales/de.json +++ b/apps/login/locales/de.json @@ -8,6 +8,10 @@ "addAnother": "Ein weiteres Konto hinzufügen", "noResults": "Keine Konten gefunden" }, + "logout": { + "title": "Logout", + "description": "Wählen Sie den Account aus, das Sie entfernen möchten" + }, "loginname": { "title": "Willkommen zurück!", "description": "Geben Sie Ihre Anmeldedaten ein.", diff --git a/apps/login/locales/en.json b/apps/login/locales/en.json index 36776ccbd9..dbf3ac6427 100644 --- a/apps/login/locales/en.json +++ b/apps/login/locales/en.json @@ -8,6 +8,10 @@ "addAnother": "Add another account", "noResults": "No accounts found" }, + "logout": { + "title": "Logout", + "description": "Select the account you want to clear" + }, "loginname": { "title": "Welcome back!", "description": "Enter your login data.", diff --git a/apps/login/locales/es.json b/apps/login/locales/es.json index 4eba3a9696..cf54ea351e 100644 --- a/apps/login/locales/es.json +++ b/apps/login/locales/es.json @@ -8,6 +8,10 @@ "addAnother": "Agregar otra cuenta", "noResults": "No se encontraron cuentas" }, + "logout": { + "title": "Cerrar sesión", + "description": "Selecciona la cuenta que deseas eliminar" + }, "loginname": { "title": "¡Bienvenido de nuevo!", "description": "Introduce tus datos de acceso.", diff --git a/apps/login/locales/it.json b/apps/login/locales/it.json index d0969c86b3..b33afc2070 100644 --- a/apps/login/locales/it.json +++ b/apps/login/locales/it.json @@ -8,6 +8,10 @@ "addAnother": "Aggiungi un altro account", "noResults": "Nessun account trovato" }, + "logout": { + "title": "Esci", + "description": "Seleziona l'account che desideri uscire" + }, "loginname": { "title": "Bentornato!", "description": "Inserisci i tuoi dati di accesso.", diff --git a/apps/login/locales/pl.json b/apps/login/locales/pl.json index 391196c49b..a0ce3405c1 100644 --- a/apps/login/locales/pl.json +++ b/apps/login/locales/pl.json @@ -8,6 +8,10 @@ "addAnother": "Dodaj kolejne konto", "noResults": "Nie znaleziono kont" }, + "logout": { + "title": "Wyloguj się", + "description": "Wybierz konto, które chcesz usunąć" + }, "loginname": { "title": "Witamy ponownie!", "description": "Wprowadź dane logowania.", diff --git a/apps/login/locales/ru.json b/apps/login/locales/ru.json index c52047897a..97f8f7200c 100644 --- a/apps/login/locales/ru.json +++ b/apps/login/locales/ru.json @@ -8,6 +8,10 @@ "addAnother": "Добавить другой аккаунт", "noResults": "Аккаунты не найдены" }, + "logout": { + "title": "Выход", + "description": "Выберите аккаунт, который хотите удалить" + }, "loginname": { "title": "С возвращением!", "description": "Введите свои данные для входа.", diff --git a/apps/login/locales/zh.json b/apps/login/locales/zh.json index 9c87a53a65..067d027ab6 100644 --- a/apps/login/locales/zh.json +++ b/apps/login/locales/zh.json @@ -8,6 +8,10 @@ "addAnother": "添加另一个账户", "noResults": "未找到账户" }, + "logout": { + "title": "注销", + "description": "选择您想注销的账户" + }, "loginname": { "title": "欢迎回来!", "description": "请输入您的登录信息。", diff --git a/apps/login/src/app/(login)/logout/page.tsx b/apps/login/src/app/(login)/logout/page.tsx new file mode 100644 index 0000000000..b5323a7117 --- /dev/null +++ b/apps/login/src/app/(login)/logout/page.tsx @@ -0,0 +1,81 @@ +import { DynamicTheme } from "@/components/dynamic-theme"; +import { SessionsList } from "@/components/sessions-list"; +import { getAllSessionCookieIds } from "@/lib/cookies"; +import { getServiceUrlFromHeaders } from "@/lib/service"; +import { + getBrandingSettings, + getDefaultOrg, + listSessions, +} from "@/lib/zitadel"; +import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb"; +import { getLocale, getTranslations } from "next-intl/server"; +import { headers } from "next/headers"; + +async function loadSessions({ serviceUrl }: { serviceUrl: string }) { + const ids: (string | undefined)[] = await getAllSessionCookieIds(); + + if (ids && ids.length) { + const response = await listSessions({ + serviceUrl, + ids: ids.filter((id) => !!id) as string[], + }); + return response?.sessions ?? []; + } else { + console.info("No session cookie found."); + return []; + } +} + +export default async function Page(props: { + searchParams: Promise>; +}) { + const searchParams = await props.searchParams; + const locale = getLocale(); + const t = await getTranslations({ locale, namespace: "logout" }); + + const requestId = searchParams?.requestId; + const organization = searchParams?.organization; + + const _headers = await headers(); + const { serviceUrl } = getServiceUrlFromHeaders(_headers); + + let defaultOrganization; + if (!organization) { + const org: Organization | null = await getDefaultOrg({ + serviceUrl, + }); + if (org) { + defaultOrganization = org.id; + } + } + + let sessions = await loadSessions({ serviceUrl }); + + const branding = await getBrandingSettings({ + serviceUrl, + organization: organization ?? defaultOrganization, + }); + + const params = new URLSearchParams(); + + if (requestId) { + params.append("requestId", requestId); + } + + if (organization) { + params.append("organization", organization); + } + + return ( + +
+

{t("title")}

+

{t("description")}

+ +
+ +
+
+
+ ); +} From a5dc44c01c3dcc8a1546b2438491090d6ae87a03 Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Mon, 28 Apr 2025 09:33:29 +0200 Subject: [PATCH 02/13] logout page --- apps/login/locales/de.json | 3 +- apps/login/locales/en.json | 3 +- apps/login/locales/es.json | 3 +- apps/login/locales/it.json | 3 +- apps/login/locales/pl.json | 3 +- apps/login/locales/ru.json | 3 +- apps/login/locales/zh.json | 3 +- apps/login/src/app/(login)/logout/page.tsx | 4 +- .../src/components/language-switcher.tsx | 4 +- .../src/components/session-clear-item.tsx | 102 ++++++++++++++++++ .../src/components/sessions-clear-list.tsx | 52 +++++++++ 11 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 apps/login/src/components/session-clear-item.tsx create mode 100644 apps/login/src/components/sessions-clear-list.tsx diff --git a/apps/login/locales/de.json b/apps/login/locales/de.json index 171f6c705d..40529341f9 100644 --- a/apps/login/locales/de.json +++ b/apps/login/locales/de.json @@ -10,7 +10,8 @@ }, "logout": { "title": "Logout", - "description": "Wählen Sie den Account aus, das Sie entfernen möchten" + "description": "Wählen Sie den Account aus, das Sie entfernen möchten", + "noResults": "Keine Konten gefunden" }, "loginname": { "title": "Willkommen zurück!", diff --git a/apps/login/locales/en.json b/apps/login/locales/en.json index dbf3ac6427..2b05693e59 100644 --- a/apps/login/locales/en.json +++ b/apps/login/locales/en.json @@ -10,7 +10,8 @@ }, "logout": { "title": "Logout", - "description": "Select the account you want to clear" + "description": "Click the accounts you want to clear", + "noResults": "No accounts found" }, "loginname": { "title": "Welcome back!", diff --git a/apps/login/locales/es.json b/apps/login/locales/es.json index cf54ea351e..c89cf2b4b2 100644 --- a/apps/login/locales/es.json +++ b/apps/login/locales/es.json @@ -10,7 +10,8 @@ }, "logout": { "title": "Cerrar sesión", - "description": "Selecciona la cuenta que deseas eliminar" + "description": "Selecciona la cuenta que deseas eliminar", + "noResults": "No se encontraron cuentas" }, "loginname": { "title": "¡Bienvenido de nuevo!", diff --git a/apps/login/locales/it.json b/apps/login/locales/it.json index b33afc2070..66ee615a47 100644 --- a/apps/login/locales/it.json +++ b/apps/login/locales/it.json @@ -10,7 +10,8 @@ }, "logout": { "title": "Esci", - "description": "Seleziona l'account che desideri uscire" + "description": "Seleziona l'account che desideri uscire", + "noResults": "Nessun account trovato" }, "loginname": { "title": "Bentornato!", diff --git a/apps/login/locales/pl.json b/apps/login/locales/pl.json index a0ce3405c1..cc65198800 100644 --- a/apps/login/locales/pl.json +++ b/apps/login/locales/pl.json @@ -10,7 +10,8 @@ }, "logout": { "title": "Wyloguj się", - "description": "Wybierz konto, które chcesz usunąć" + "description": "Wybierz konto, które chcesz usunąć", + "noResults": "Nie znaleziono kont" }, "loginname": { "title": "Witamy ponownie!", diff --git a/apps/login/locales/ru.json b/apps/login/locales/ru.json index 97f8f7200c..766b956734 100644 --- a/apps/login/locales/ru.json +++ b/apps/login/locales/ru.json @@ -10,7 +10,8 @@ }, "logout": { "title": "Выход", - "description": "Выберите аккаунт, который хотите удалить" + "description": "Выберите аккаунт, который хотите удалить", + "noResults": "Аккаунты не найдены" }, "loginname": { "title": "С возвращением!", diff --git a/apps/login/locales/zh.json b/apps/login/locales/zh.json index 067d027ab6..fb34dfcbe3 100644 --- a/apps/login/locales/zh.json +++ b/apps/login/locales/zh.json @@ -10,7 +10,8 @@ }, "logout": { "title": "注销", - "description": "选择您想注销的账户" + "description": "选择您想注销的账户", + "noResults": "未找到账户" }, "loginname": { "title": "欢迎回来!", diff --git a/apps/login/src/app/(login)/logout/page.tsx b/apps/login/src/app/(login)/logout/page.tsx index b5323a7117..d15ead76a1 100644 --- a/apps/login/src/app/(login)/logout/page.tsx +++ b/apps/login/src/app/(login)/logout/page.tsx @@ -1,5 +1,5 @@ import { DynamicTheme } from "@/components/dynamic-theme"; -import { SessionsList } from "@/components/sessions-list"; +import { SessionsClearList } from "@/components/sessions-clear-list"; import { getAllSessionCookieIds } from "@/lib/cookies"; import { getServiceUrlFromHeaders } from "@/lib/service"; import { @@ -73,7 +73,7 @@ export default async function Page(props: {

{t("description")}

- +
diff --git a/apps/login/src/components/language-switcher.tsx b/apps/login/src/components/language-switcher.tsx index 8d68248c4a..67b54e58e3 100644 --- a/apps/login/src/components/language-switcher.tsx +++ b/apps/login/src/components/language-switcher.tsx @@ -43,7 +43,7 @@ export function LanguageSwitcher() { > {selected.name}