From 5ea5797a75f2674b2f420f564b721f2c56f81135 Mon Sep 17 00:00:00 2001 From: nael Date: Thu, 18 Apr 2024 07:52:58 +0200 Subject: [PATCH] :coffin: Dead code --- .../src/app/auth/[slug]/dashboard/layout.tsx | 16 -- .../[slug]/dashboard/oidc/[connection_id].tsx | 221 ------------------ .../src/app/auth/[slug]/dashboard/page.tsx | 83 ------- .../[slug]/dashboard/saml/[connection_id].tsx | 182 --------------- .../src/app/auth/[slug]/login/page.tsx | 43 ---- .../src/app/auth/[slug]/smsmfa/index.tsx | 22 -- .../client-ts/src/app/auth/discovery/page.tsx | 9 - apps/client-ts/src/app/auth/login/page.tsx | 26 --- .../src/app/auth/orgswitcher/layout.tsx | 16 -- .../src/app/auth/orgswitcher/page.tsx | 103 -------- apps/client-ts/src/app/auth/page.tsx | 5 - apps/client-ts/src/app/auth/register/page.tsx | 16 -- 12 files changed, 742 deletions(-) delete mode 100644 apps/client-ts/src/app/auth/[slug]/dashboard/layout.tsx delete mode 100644 apps/client-ts/src/app/auth/[slug]/dashboard/oidc/[connection_id].tsx delete mode 100644 apps/client-ts/src/app/auth/[slug]/dashboard/page.tsx delete mode 100644 apps/client-ts/src/app/auth/[slug]/dashboard/saml/[connection_id].tsx delete mode 100644 apps/client-ts/src/app/auth/[slug]/login/page.tsx delete mode 100644 apps/client-ts/src/app/auth/[slug]/smsmfa/index.tsx delete mode 100644 apps/client-ts/src/app/auth/discovery/page.tsx delete mode 100644 apps/client-ts/src/app/auth/login/page.tsx delete mode 100644 apps/client-ts/src/app/auth/orgswitcher/layout.tsx delete mode 100644 apps/client-ts/src/app/auth/orgswitcher/page.tsx delete mode 100644 apps/client-ts/src/app/auth/page.tsx delete mode 100644 apps/client-ts/src/app/auth/register/page.tsx diff --git a/apps/client-ts/src/app/auth/[slug]/dashboard/layout.tsx b/apps/client-ts/src/app/auth/[slug]/dashboard/layout.tsx deleted file mode 100644 index 522db8533..000000000 --- a/apps/client-ts/src/app/auth/[slug]/dashboard/layout.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import "./../../../globals.css"; -import { RootLayout } from "@/components/RootLayout"; - - -export default function Layout({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) { - return ( - <> - - {children} - - ); -} diff --git a/apps/client-ts/src/app/auth/[slug]/dashboard/oidc/[connection_id].tsx b/apps/client-ts/src/app/auth/[slug]/dashboard/oidc/[connection_id].tsx deleted file mode 100644 index ec654054a..000000000 --- a/apps/client-ts/src/app/auth/[slug]/dashboard/oidc/[connection_id].tsx +++ /dev/null @@ -1,221 +0,0 @@ -import {findByID} from "@/lib/stytch/orgService"; -import { FormEventHandler } from "react"; -import { updateOidcSSOConn } from "@/lib/stytch/api"; -import { usePathname, useRouter, useSearchParams } from "next/navigation"; -import loadStytch, { formatSSOStartURL } from "@/lib/stytch/loadStytch"; -import { getAuthData } from "@/lib/stytch/sessionService"; -import Link from "next/link"; -import { list } from "@/lib/stytch/ssoService"; -import {getDomainFromRequest} from "@/lib/stytch/urlUtils"; -import { cookies, headers } from "next/headers"; -import { Input } from "@/components/ui/input" -import { OIDCConnection } from "stytch"; - -const stytch = loadStytch(); - -async function getProps(connection_id: string | null) { - const sessionJWT = cookies().get("session"); - - if (!sessionJWT) { - throw new Error("no jwt set"); - //return NextResponse.redirect(new URL('/auth/login', request.url)); - } - let sessionAuthRes; - try { - sessionAuthRes = await stytch.sessions.authenticate({ - session_duration_minutes: 30, - session_jwt: sessionJWT.value, - }); - console.log("sessionauthres is "+ JSON.stringify(sessionAuthRes)); - } catch (err) { - console.log(err); - return err; - } const { member } = getAuthData(JSON.stringify(sessionAuthRes)); - const host = headers().get('host') - const protocol = headers().get('x-forwarded-proto') - - const org = await findByID(member.organization_id); - if (org === null) { - return { redirect: { statusCode: 307, destination: `/auth/login` } }; - } - - const connection = await list(org.organization_id).then((res) => { - return res.oidc_connections.find( - (conn) => conn.connection_id === connection_id - ); - }); - - if (!connection) { - return { - redirect: { - statusCode: 307, - destination: `/auth/${org.organization_slug}/dashboard`, - }, - }; - } - - return { - connection: connection, - domain: getDomainFromRequest(host!, protocol!), - }; -} - -interface ResponseProps { - connection: OIDCConnection; - domain: string; -} - -async function ConnectionEditPage() { - const pathname = usePathname() - const searchParams = useSearchParams() - const router = useRouter(); - const connection_id = searchParams.get("connection_id"); - - const {connection, domain} = await getProps(connection_id as string) as ResponseProps; - // @ts-ignore - const urlSectionClick = (e) => { - e.preventDefault(); - var panel = e.target.nextElementSibling; - if (panel.style.display === "block") { - panel.style.display = "none"; - } else { - panel.style.display = "block"; - } - }; - - const onSubmit: FormEventHandler = async (e) => { - e.preventDefault(); - const data = new FormData(e.target as HTMLFormElement); - - await updateOidcSSOConn({ - connection_id: connection!.connection_id, - display_name: data.get("display_name") as string, - client_id: data.get("client_id") as string, - client_secret: data.get("client_secret") as string, - issuer: data.get("issuer") as string, - authorization_url: data.get("authorization_url") as string, - token_url: data.get("token_url") as string, - userinfo_url: data.get("userinfo_url") as string, - jwks_url: data.get("jwks_url") as string, - }); - - // Force a reload to refresh the conn list - router.replace(pathname); - }; - - return ( - <> -
-
-

Edit OIDC Connection

- - - - - - - - - - - - - - -
-
- If you provide a valid Issuer URL using an IDP that supports a - well-known configuration page, these endpoints will be - auto-populated. -
- -
-
- - - - - - - - -
-
- -
- - - - - Back - -
- - ); -} - - -export default ConnectionEditPage; diff --git a/apps/client-ts/src/app/auth/[slug]/dashboard/page.tsx b/apps/client-ts/src/app/auth/[slug]/dashboard/page.tsx deleted file mode 100644 index 92149a2d3..000000000 --- a/apps/client-ts/src/app/auth/[slug]/dashboard/page.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { getAuthData } from "@/lib/stytch/sessionService"; -import { findAllMembers, findByID } from "@/lib/stytch/orgService"; -import { list } from "@/lib/stytch/ssoService"; -import { cookies } from "next/headers"; -import DashboardClient from "@/components/Auth/DashboardClient"; -import loadStytch, { Member, OIDCConnection, Organization, SAMLConnection } from "@/lib/stytch/loadStytch"; - -const stytch = loadStytch(); - -interface ResultProps { - props: { - org: Organization; // Replace with actual type - user: Member; // Replace with actual type - members: Member[]; // Replace with actual type - saml_connections: SAMLConnection[]; // Replace with actual type - oidc_connections: OIDCConnection[]; // Replace with actual type - }; -} - -async function getProps() { - const sessionJWT = cookies().get("session"); - - if (!sessionJWT) { - throw new Error("no jwt set"); - //return NextResponse.redirect(new URL('/auth/login', request.url)); - } - let sessionAuthRes; - try { - sessionAuthRes = await stytch.sessions.authenticate({ - session_duration_minutes: 30, - session_jwt: sessionJWT.value, - }); - console.log("sessionauthres is "+ JSON.stringify(sessionAuthRes)); - } catch (err) { - console.log(err); - return err; - } - - const { member } = getAuthData(JSON.stringify(sessionAuthRes)); - const org = await findByID(member.organization_id); - - if (org === null) { - return { redirect: { statusCode: 307, destination: `/auth/login` } }; - } - - const [members, ssoConnections] = await Promise.all([ - findAllMembers(org.organization_id), - list(org.organization_id), - ]); - - return { - props: { - org, - user: member, - members, - saml_connections: ssoConnections.saml_connections ?? [], - oidc_connections: ssoConnections.oidc_connections ?? [], - }, - }; -} - -const Dashboard = async () => { - const result: ResultProps = await getProps() as ResultProps; - - if (!result.props) { - return null; - } - - const { - org, - user, - members, - saml_connections, - oidc_connections, - } = result.props; - - return ( - - ); -}; - - -export default Dashboard; diff --git a/apps/client-ts/src/app/auth/[slug]/dashboard/saml/[connection_id].tsx b/apps/client-ts/src/app/auth/[slug]/dashboard/saml/[connection_id].tsx deleted file mode 100644 index 82396483a..000000000 --- a/apps/client-ts/src/app/auth/[slug]/dashboard/saml/[connection_id].tsx +++ /dev/null @@ -1,182 +0,0 @@ -import { findByID } from "@/lib/stytch/orgService"; -import { FormEventHandler } from "react"; -import { updateSamlSSOConn } from "@/lib/stytch/api"; -import { usePathname, useRouter, useSearchParams } from "next/navigation"; -import loadStytch, { formatSSOStartURL } from "@/lib/stytch/loadStytch"; -import { getAuthData} from "@/lib/stytch/sessionService"; -import Link from "next/link"; -import { list } from "@/lib/stytch/ssoService"; -import {getDomainFromRequest} from "@/lib/stytch/urlUtils"; -import { cookies, headers } from "next/headers"; -import { Input } from "@/components/ui/input" -import { SAMLConnection } from "stytch"; - -const stytch = loadStytch(); - -async function getProps(connection_id: string) { - const sessionJWT = cookies().get("session"); - - if (!sessionJWT) { - throw new Error("no jwt set"); - //return NextResponse.redirect(new URL('/auth/login', request.url)); - } - let sessionAuthRes; - try { - sessionAuthRes = await stytch.sessions.authenticate({ - session_duration_minutes: 30, - session_jwt: sessionJWT.value, - }); - console.log("sessionauthres is "+ JSON.stringify(sessionAuthRes)); - } catch (err) { - console.log(err); - return err; - } - - const { member } = getAuthData(JSON.stringify(sessionAuthRes)); - - const org = await findByID(member.organization_id); - if (org === null) { - return { redirect: { statusCode: 307, destination: `/auth/login` } }; - } - - const connection = await list(org.organization_id).then((res) => - res.saml_connections.find((conn) => conn.connection_id === connection_id) - ); - - if (!connection) { - return { - redirect: { - statusCode: 307, - destination: `/auth/${org.organization_slug}/dashboard`, - }, - }; - } - const host = headers().get('host') - const protocol = headers().get('x-forwarded-proto') - - return { - connection: connection, - domain: getDomainFromRequest(host!, protocol!) - }; -} -interface ResponseProps { - connection: SAMLConnection; - domain: string; -} -async function ConnectionEditPage() { - const router = useRouter(); - const pathname = usePathname() - const searchParams = useSearchParams() - const connection_id = searchParams.get("connection_id"); - - const {connection, domain} = await getProps(connection_id as string) as ResponseProps; - - const onSubmit: FormEventHandler = async (e) => { - e.preventDefault(); - const data = new FormData(e.target as HTMLFormElement); - - await updateSamlSSOConn({ - certificate: data.get("certificate") as string, - connection_id: connection!.connection_id, - display_name: data.get("display_name") as string, - email_attribute: data.get("email_attribute") as string, - first_name_attribute: data.get("first_name_attribute") as string, - idp_entity_id: data.get("idp_entity_id") as string, - idp_sso_url: data.get("idp_sso_url") as string, - last_name_attribute: data.get("last_name_attribute") as string, - }); - - // Force a reload to refresh the conn list - router.replace(pathname); - }; - - return ( - <> -
-
-

Edit SAML Connection

- - - - - - - - - - - - - - - - - - - -