1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-23 11:02:35 +03:00

get session and display as session tile on session detail page

This commit is contained in:
Kerry Archibald
2023-08-31 16:21:27 +12:00
committed by Quentin Gliech
parent 301b1327c5
commit 915ebc9dfd
3 changed files with 243 additions and 4 deletions

View File

@@ -12,15 +12,71 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Alert, Body } from "@vector-im/compound-web";
import { useAtomValue } from "jotai";
import { atomFamily } from "jotai/utils";
import { atomWithQuery } from "jotai-urql";
import { useRef } from "react";
import { Link } from "../../Router";
import { graphql } from "../../gql/gql";
import CompatSession from "../CompatSession";
import OAuth2Session from "../OAuth2Session";
const QUERY = graphql(/* GraphQL */ `
query SessionQuery($userId: ID!, $deviceId: String!) {
session(userId: $userId, deviceId: $deviceId) {
__typename
...CompatSession_session
...OAuth2Session_session
}
}
`);
const sessionFamily = atomFamily(
({ userId, deviceId }: { userId: string; deviceId: string }) => {
const sessionQueryAtom = atomWithQuery({
query: QUERY,
getVariables: () => ({ userId, deviceId }),
});
return sessionQueryAtom;
},
);
const SessionDetail: React.FC<{ const SessionDetail: React.FC<{
deviceId: string; deviceId: string;
userId: string; userId: string;
}> = ({ deviceId, userId }) => { }> = ({ deviceId, userId }) => {
const props = useRef({ userId, deviceId });
const result = useAtomValue(sessionFamily(props.current));
const session = result.data?.session;
if (!session) {
// TODO put a back button here
return (
<Alert type="critical" title="Error">
<Body>Cannot find session: {deviceId}</Body>
<Link kind="button" route={{ type: "sessions-overview" }}>
Go back
</Link>
</Alert>
);
}
const sessionType = session.__typename;
if (sessionType === "Oauth2Session") {
return <OAuth2Session session={session} />;
} else if (sessionType === "CompatSession") {
return <CompatSession session={session} />;
}
return ( return (
<> <Alert title="Error" type="critical">
<code>deviceId: {deviceId}</code> Unexpected session type
<code>userId: {userId}</code> </Alert>
</>
); );
}; };

View File

@@ -37,6 +37,8 @@ const documents = {
types.EndOAuth2SessionDocument, types.EndOAuth2SessionDocument,
"\n query OAuth2SessionListQuery(\n $userId: ID!\n $state: Oauth2SessionState\n $first: Int\n $after: String\n $last: Int\n $before: String\n ) {\n user(id: $userId) {\n id\n oauth2Sessions(\n state: $state\n first: $first\n after: $after\n last: $last\n before: $before\n ) {\n edges {\n cursor\n node {\n id\n ...OAuth2Session_session\n }\n }\n\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n": "\n query OAuth2SessionListQuery(\n $userId: ID!\n $state: Oauth2SessionState\n $first: Int\n $after: String\n $last: Int\n $before: String\n ) {\n user(id: $userId) {\n id\n oauth2Sessions(\n state: $state\n first: $first\n after: $after\n last: $last\n before: $before\n ) {\n edges {\n cursor\n node {\n id\n ...OAuth2Session_session\n }\n }\n\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n":
types.OAuth2SessionListQueryDocument, types.OAuth2SessionListQueryDocument,
"\n query SessionQuery($userId: ID!, $deviceId: String!) {\n session(userId: $userId, deviceId: $deviceId) {\n __typename\n ...CompatSession_session\n ...OAuth2Session_session\n }\n }\n":
types.SessionQueryDocument,
"\n fragment UnverifiedEmailAlert on User {\n id\n unverifiedEmails: emails(first: 0, state: PENDING) {\n totalCount\n }\n }\n": "\n fragment UnverifiedEmailAlert on User {\n id\n unverifiedEmails: emails(first: 0, state: PENDING) {\n totalCount\n }\n }\n":
types.UnverifiedEmailAlertFragmentDoc, types.UnverifiedEmailAlertFragmentDoc,
"\n fragment UserEmail_email on UserEmail {\n id\n email\n confirmedAt\n }\n": "\n fragment UserEmail_email on UserEmail {\n id\n email\n confirmedAt\n }\n":
@@ -159,6 +161,12 @@ export function graphql(
export function graphql( export function graphql(
source: "\n query OAuth2SessionListQuery(\n $userId: ID!\n $state: Oauth2SessionState\n $first: Int\n $after: String\n $last: Int\n $before: String\n ) {\n user(id: $userId) {\n id\n oauth2Sessions(\n state: $state\n first: $first\n after: $after\n last: $last\n before: $before\n ) {\n edges {\n cursor\n node {\n id\n ...OAuth2Session_session\n }\n }\n\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n", source: "\n query OAuth2SessionListQuery(\n $userId: ID!\n $state: Oauth2SessionState\n $first: Int\n $after: String\n $last: Int\n $before: String\n ) {\n user(id: $userId) {\n id\n oauth2Sessions(\n state: $state\n first: $first\n after: $after\n last: $last\n before: $before\n ) {\n edges {\n cursor\n node {\n id\n ...OAuth2Session_session\n }\n }\n\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n",
): (typeof documents)["\n query OAuth2SessionListQuery(\n $userId: ID!\n $state: Oauth2SessionState\n $first: Int\n $after: String\n $last: Int\n $before: String\n ) {\n user(id: $userId) {\n id\n oauth2Sessions(\n state: $state\n first: $first\n after: $after\n last: $last\n before: $before\n ) {\n edges {\n cursor\n node {\n id\n ...OAuth2Session_session\n }\n }\n\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n"]; ): (typeof documents)["\n query OAuth2SessionListQuery(\n $userId: ID!\n $state: Oauth2SessionState\n $first: Int\n $after: String\n $last: Int\n $before: String\n ) {\n user(id: $userId) {\n id\n oauth2Sessions(\n state: $state\n first: $first\n after: $after\n last: $last\n before: $before\n ) {\n edges {\n cursor\n node {\n id\n ...OAuth2Session_session\n }\n }\n\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: "\n query SessionQuery($userId: ID!, $deviceId: String!) {\n session(userId: $userId, deviceId: $deviceId) {\n __typename\n ...CompatSession_session\n ...OAuth2Session_session\n }\n }\n",
): (typeof documents)["\n query SessionQuery($userId: ID!, $deviceId: String!) {\n session(userId: $userId, deviceId: $deviceId) {\n __typename\n ...CompatSession_session\n ...OAuth2Session_session\n }\n }\n"];
/** /**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/ */

View File

@@ -1146,6 +1146,27 @@ export type OAuth2SessionListQueryQuery = {
} | null; } | null;
}; };
export type SessionQueryQueryVariables = Exact<{
userId: Scalars["ID"]["input"];
deviceId: Scalars["String"]["input"];
}>;
export type SessionQueryQuery = {
__typename?: "Query";
session?:
| ({ __typename: "CompatSession" } & {
" $fragmentRefs"?: {
CompatSession_SessionFragment: CompatSession_SessionFragment;
};
})
| ({ __typename: "Oauth2Session" } & {
" $fragmentRefs"?: {
OAuth2Session_SessionFragment: OAuth2Session_SessionFragment;
};
})
| null;
};
export type UnverifiedEmailAlertFragment = { export type UnverifiedEmailAlertFragment = {
__typename?: "User"; __typename?: "User";
id: string; id: string;
@@ -2891,6 +2912,160 @@ export const OAuth2SessionListQueryDocument = {
OAuth2SessionListQueryQuery, OAuth2SessionListQueryQuery,
OAuth2SessionListQueryQueryVariables OAuth2SessionListQueryQueryVariables
>; >;
export const SessionQueryDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "query",
name: { kind: "Name", value: "SessionQuery" },
variableDefinitions: [
{
kind: "VariableDefinition",
variable: {
kind: "Variable",
name: { kind: "Name", value: "userId" },
},
type: {
kind: "NonNullType",
type: { kind: "NamedType", name: { kind: "Name", value: "ID" } },
},
},
{
kind: "VariableDefinition",
variable: {
kind: "Variable",
name: { kind: "Name", value: "deviceId" },
},
type: {
kind: "NonNullType",
type: {
kind: "NamedType",
name: { kind: "Name", value: "String" },
},
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "session" },
arguments: [
{
kind: "Argument",
name: { kind: "Name", value: "userId" },
value: {
kind: "Variable",
name: { kind: "Name", value: "userId" },
},
},
{
kind: "Argument",
name: { kind: "Name", value: "deviceId" },
value: {
kind: "Variable",
name: { kind: "Name", value: "deviceId" },
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "__typename" } },
{
kind: "FragmentSpread",
name: { kind: "Name", value: "CompatSession_session" },
},
{
kind: "FragmentSpread",
name: { kind: "Name", value: "OAuth2Session_session" },
},
],
},
},
],
},
},
{
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" },
typeCondition: {
kind: "NamedType",
name: { kind: "Name", value: "CompatSession" },
},
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
{ kind: "Field", name: { kind: "Name", value: "createdAt" } },
{ kind: "Field", name: { kind: "Name", value: "deviceId" } },
{ kind: "Field", name: { kind: "Name", value: "finishedAt" } },
{
kind: "Field",
name: { kind: "Name", value: "ssoLogin" },
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
{
kind: "FragmentSpread",
name: { kind: "Name", value: "CompatSession_sso_login" },
},
],
},
},
],
},
},
{
kind: "FragmentDefinition",
name: { kind: "Name", value: "OAuth2Session_session" },
typeCondition: {
kind: "NamedType",
name: { kind: "Name", value: "Oauth2Session" },
},
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
{ kind: "Field", name: { kind: "Name", value: "scope" } },
{ kind: "Field", name: { kind: "Name", value: "createdAt" } },
{ kind: "Field", name: { kind: "Name", value: "finishedAt" } },
{
kind: "Field",
name: { kind: "Name", value: "client" },
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
{ kind: "Field", name: { kind: "Name", value: "clientId" } },
{ kind: "Field", name: { kind: "Name", value: "clientName" } },
{ kind: "Field", name: { kind: "Name", value: "clientUri" } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<SessionQueryQuery, SessionQueryQueryVariables>;
export const RemoveEmailDocument = { export const RemoveEmailDocument = {
kind: "Document", kind: "Document",
definitions: [ definitions: [