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

bust cache after verifying email

This commit is contained in:
Kerry Archibald
2023-09-15 10:05:19 +12:00
committed by Quentin Gliech
parent e9f11a7cd9
commit 8eec9e53a7

View File

@@ -21,7 +21,9 @@ import { requestPolicyExchange } from "@urql/exchange-request-policy";
import type {
MutationAddEmailArgs,
MutationRemoveEmailArgs,
MutationVerifyEmailArgs,
RemoveEmailPayload,
VerifyEmailPayload,
} from "./gql/graphql";
import schema from "./gql/schema";
@@ -77,6 +79,36 @@ const cache = cacheExchange({
});
}
},
verifyEmail: (
result: { verifyEmail?: VerifyEmailPayload },
args: MutationVerifyEmailArgs,
cache,
_info,
) => {
// Invalidate the email entity
cache.invalidate({
__typename: "UserEmail",
id: args.input.userEmailId,
});
// Let's try to figure out the userId to invalidate the emails field on the User object
const userId = result.verifyEmail?.user?.id;
if (userId) {
const key = cache.keyOfEntity({
__typename: "User",
id: userId,
});
// Invalidate the emails field on the User object so that it gets refetched
cache
.inspectFields(key)
.filter((field) => field.fieldName === "emails")
.forEach((field) => {
cache.invalidate(key, field.fieldName, field.arguments);
});
}
},
},
},
});