diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9615961a07d..aad7d0a598c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,6 @@ jobs: - name: Install Dependencies id: deps run: pnpm install - - name: Generate Stubs - id: grpc - run: pnpm generate - name: Test id: test run: pnpm test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53f031c6c56..11bf44f3af8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,11 +50,11 @@ You can execute the following commands in the following directories: - The projects root directory: all tests in the project are executed ```sh -# Run unit and integration tests once -pnpm run test -- --passWithNoTests +# Run all once +pnpm test -# Rerun unit and integration tests on file changes -pnpm run test:watch -- --passWithNoTests +# Rerun tests on file changes +pnpm test:watch ``` ### Developing Against Your Local ZITADEL Instance diff --git a/apps/login/app/(login)/accounts/page.tsx b/apps/login/app/(login)/accounts/page.tsx index b280580ce8c..b3b0631e162 100644 --- a/apps/login/app/(login)/accounts/page.tsx +++ b/apps/login/app/(login)/accounts/page.tsx @@ -1,11 +1,9 @@ -import { Session } from "#/../../packages/zitadel-server/dist"; +import { Session } from "@zitadel/server"; import { listSessions, server } from "#/lib/zitadel"; -import Alert from "#/ui/Alert"; -import { Avatar } from "#/ui/Avatar"; import { getAllSessionIds } from "#/utils/cookies"; -import { UserPlusIcon, XCircleIcon } from "@heroicons/react/24/outline"; -import moment from "moment"; +import { UserPlusIcon } from "@heroicons/react/24/outline"; import Link from "next/link"; +import SessionsList from "#/ui/SessionsList"; async function loadSessions(): Promise { const ids = await getAllSessionIds(); @@ -23,7 +21,7 @@ async function loadSessions(): Promise { } export default async function Page() { - const sessions = await loadSessions(); + let sessions = await loadSessions(); return (
@@ -31,65 +29,7 @@ export default async function Page() {

Use your ZITADEL Account

- {sessions ? ( - sessions - .filter((session) => session?.factors?.user?.loginName) - .map((session, index) => { - const validPassword = session?.factors?.password?.verifiedAt; - return ( - -
- -
- -
- - {session.factors?.user?.displayName} - - - {session.factors?.user?.loginName} - - {validPassword && ( - - {moment(new Date(validPassword)).fromNow()} - - )} -
- - -
- {validPassword ? ( -
- ) : ( -
- )} - - -
- - ); - }) - ) : ( - No Sessions available! - )} +
diff --git a/apps/login/app/session/route.ts b/apps/login/app/session/route.ts index 142f5bf51f2..0d4da683874 100644 --- a/apps/login/app/session/route.ts +++ b/apps/login/app/session/route.ts @@ -1,8 +1,16 @@ -import { createSession, getSession, server, setSession } from "#/lib/zitadel"; +import { + createSession, + getSession, + server, + setSession, + deleteSession, +} from "#/lib/zitadel"; import { SessionCookie, addSessionToCookie, getMostRecentSessionCookie, + getSessionCookieById, + removeSessionFromCookie, updateSessionCookie, } from "#/utils/cookies"; import { NextRequest, NextResponse } from "next/server"; @@ -115,10 +123,43 @@ export async function PUT(request: NextRequest) { } }) .catch((error) => { - console.error("erasd", error); return NextResponse.json(error, { status: 500 }); }); } else { return NextResponse.error(); } } + +/** + * + * @param request id of the session to be deleted + */ +export async function DELETE(request: NextRequest) { + const { searchParams } = new URL(request.url); + const id = searchParams.get("id"); + if (id) { + const session = await getSessionCookieById(id); + + return deleteSession(server, session.id, session.token) + .then(() => { + return removeSessionFromCookie(session) + .then(() => { + return NextResponse.json({ factors: session.factors }); + }) + .catch((error) => { + return NextResponse.json( + { details: "could not set cookie" }, + { status: 500 } + ); + }); + }) + .catch((error) => { + return NextResponse.json( + { details: "could not delete session" }, + { status: 500 } + ); + }); + } else { + return NextResponse.error(); + } +} diff --git a/apps/login/lib/zitadel.ts b/apps/login/lib/zitadel.ts index 4d514d1758e..b44b4793420 100644 --- a/apps/login/lib/zitadel.ts +++ b/apps/login/lib/zitadel.ts @@ -19,6 +19,7 @@ import { GetSessionResponse, VerifyEmailResponse, SetSessionResponse, + DeleteSessionResponse, } from "@zitadel/server"; export const zitadelConfig: ZitadelServerOptions = { @@ -103,6 +104,15 @@ export function getSession( return sessionService.getSession({ sessionId, sessionToken }, {}); } +export function deleteSession( + server: ZitadelServer, + sessionId: string, + sessionToken: string +): Promise { + const sessionService = session.getSession(server); + return sessionService.deleteSession({ sessionId, sessionToken }, {}); +} + export function listSessions( server: ZitadelServer, ids: string[] diff --git a/apps/login/ui/Input.tsx b/apps/login/ui/Input.tsx index 55887fbdb1a..3c7de28b1f1 100644 --- a/apps/login/ui/Input.tsx +++ b/apps/login/ui/Input.tsx @@ -8,7 +8,6 @@ import React, { InputHTMLAttributes, ReactNode, } from "react"; -import { v4 as uuidv4 } from "uuid"; export type TextInputProps = DetailedHTMLProps< InputHTMLAttributes, @@ -55,7 +54,6 @@ export const TextInput = forwardRef( }, ref ) => { - const id = uuidv4(); return (