diff --git a/frontend/src/components/CompatSession.tsx b/frontend/src/components/CompatSession.tsx
index 6a80f18c..5c36a245 100644
--- a/frontend/src/components/CompatSession.tsx
+++ b/frontend/src/components/CompatSession.tsx
@@ -22,14 +22,6 @@ import { FragmentType, graphql, useFragment } from "../gql";
import { Session } from "./Session";
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-const LOGIN_FRAGMENT = graphql(/* GraphQL */ `
- fragment CompatSession_sso_login on CompatSsoLogin {
- id
- redirectUri
- }
-`);
-
export const COMPAT_SESSION_FRAGMENT = graphql(/* GraphQL */ `
fragment CompatSession_session on CompatSession {
id
@@ -38,22 +30,11 @@ export const COMPAT_SESSION_FRAGMENT = graphql(/* GraphQL */ `
finishedAt
ssoLogin {
id
- ...CompatSession_sso_login
+ redirectUri
}
}
`);
-type CompatSessionType = {
- id: string;
- deviceId: string;
- createdAt: string;
- finishedAt: string | null;
- ssoLogin: {
- id: string;
- redirectUri: string;
- };
-};
-
const END_SESSION_MUTATION = graphql(/* GraphQL */ `
mutation EndCompatSession($id: ID!) {
endCompatSession(input: { compatSessionId: $id }) {
@@ -78,14 +59,32 @@ const endCompatSessionFamily = atomFamily((id: string) => {
return endCompatSessionAtom;
});
+const simplifyUrl = (url: string): string => {
+ let parsed;
+ try {
+ parsed = new URL(url);
+ } catch (e) {
+ // Not a valid URL, return the original
+ return url;
+ }
+
+ // Clear out the search params and hash
+ parsed.search = "";
+ parsed.hash = "";
+
+ if (parsed.protocol === "https:") {
+ return parsed.hostname;
+ }
+
+ // Return the simplified URL
+ return parsed.toString();
+};
+
const CompatSession: React.FC<{
session: FragmentType;
}> = ({ session }) => {
const [pending, startTransition] = useTransition();
- const data = useFragment(
- COMPAT_SESSION_FRAGMENT,
- session,
- ) as CompatSessionType;
+ const data = useFragment(COMPAT_SESSION_FRAGMENT, session);
const endCompatSession = useSetAtom(endCompatSessionFamily(data.id));
const onSessionEnd = (): void => {
@@ -94,13 +93,17 @@ const CompatSession: React.FC<{
});
};
+ const clientName = data.ssoLogin?.redirectUri
+ ? simplifyUrl(data.ssoLogin.redirectUri)
+ : undefined;
+
return (
{!data.finishedAt && (
> renders a finished session 1`] = `
- https://element.io
+ element.io
@@ -67,7 +67,7 @@ exports[` > renders an active session 1`] = `
- https://element.io
+ element.io
;
-export const CompatSession_Sso_LoginFragmentDoc = {
- kind: "Document",
- definitions: [
- {
- kind: "FragmentDefinition",
- name: { kind: "Name", value: "CompatSession_sso_login" },
- typeCondition: {
- kind: "NamedType",
- name: { kind: "Name", value: "CompatSsoLogin" },
- },
- selectionSet: {
- kind: "SelectionSet",
- selections: [
- { kind: "Field", name: { kind: "Name", value: "id" } },
- { kind: "Field", name: { kind: "Name", value: "redirectUri" } },
- ],
- },
- },
- ],
-} as unknown as DocumentNode;
export const CompatSession_SessionFragmentDoc = {
kind: "Document",
definitions: [
@@ -1540,31 +1512,13 @@ export const CompatSession_SessionFragmentDoc = {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
- {
- kind: "FragmentSpread",
- name: { kind: "Name", value: "CompatSession_sso_login" },
- },
+ { kind: "Field", name: { kind: "Name", value: "redirectUri" } },
],
},
},
],
},
},
- {
- kind: "FragmentDefinition",
- name: { kind: "Name", value: "CompatSession_sso_login" },
- typeCondition: {
- kind: "NamedType",
- name: { kind: "Name", value: "CompatSsoLogin" },
- },
- selectionSet: {
- kind: "SelectionSet",
- selections: [
- { kind: "Field", name: { kind: "Name", value: "id" } },
- { kind: "Field", name: { kind: "Name", value: "redirectUri" } },
- ],
- },
- },
],
} as unknown as DocumentNode;
export const OAuth2Session_SessionFragmentDoc = {
@@ -2526,21 +2480,6 @@ export const CompatSessionListDocument = {
],
},
},
- {
- kind: "FragmentDefinition",
- name: { kind: "Name", value: "CompatSession_sso_login" },
- typeCondition: {
- kind: "NamedType",
- name: { kind: "Name", value: "CompatSsoLogin" },
- },
- selectionSet: {
- kind: "SelectionSet",
- selections: [
- { kind: "Field", name: { kind: "Name", value: "id" } },
- { kind: "Field", name: { kind: "Name", value: "redirectUri" } },
- ],
- },
- },
{
kind: "FragmentDefinition",
name: { kind: "Name", value: "CompatSession_session" },
@@ -2562,10 +2501,7 @@ export const CompatSessionListDocument = {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
- {
- kind: "FragmentSpread",
- name: { kind: "Name", value: "CompatSession_sso_login" },
- },
+ { kind: "Field", name: { kind: "Name", value: "redirectUri" } },
],
},
},
@@ -2988,21 +2924,6 @@ export const SessionQueryDocument = {
],
},
},
- {
- kind: "FragmentDefinition",
- name: { kind: "Name", value: "CompatSession_sso_login" },
- typeCondition: {
- kind: "NamedType",
- name: { kind: "Name", value: "CompatSsoLogin" },
- },
- selectionSet: {
- kind: "SelectionSet",
- selections: [
- { kind: "Field", name: { kind: "Name", value: "id" } },
- { kind: "Field", name: { kind: "Name", value: "redirectUri" } },
- ],
- },
- },
{
kind: "FragmentDefinition",
name: { kind: "Name", value: "CompatSession_session" },
@@ -3024,10 +2945,7 @@ export const SessionQueryDocument = {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
- {
- kind: "FragmentSpread",
- name: { kind: "Name", value: "CompatSession_sso_login" },
- },
+ { kind: "Field", name: { kind: "Name", value: "redirectUri" } },
],
},
},