You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-24 23:01:05 +03:00
bust cache after verifying email
This commit is contained in:
committed by
Quentin Gliech
parent
e9f11a7cd9
commit
8eec9e53a7
@@ -21,7 +21,9 @@ import { requestPolicyExchange } from "@urql/exchange-request-policy";
|
|||||||
import type {
|
import type {
|
||||||
MutationAddEmailArgs,
|
MutationAddEmailArgs,
|
||||||
MutationRemoveEmailArgs,
|
MutationRemoveEmailArgs,
|
||||||
|
MutationVerifyEmailArgs,
|
||||||
RemoveEmailPayload,
|
RemoveEmailPayload,
|
||||||
|
VerifyEmailPayload,
|
||||||
} from "./gql/graphql";
|
} from "./gql/graphql";
|
||||||
import schema from "./gql/schema";
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user