confirmEmailChange method
Confirms auth record new email address.
If the current AuthStore.record matches with the record from the token, then on success the client AuthStore will be also cleared.
Implementation
Future<void> confirmEmailChange(
String emailChangeToken,
String userPassword, {
Map<String, dynamic> body = const {},
Map<String, dynamic> query = const {},
Map<String, String> headers = const {},
}) {
final enrichedBody = Map<String, dynamic>.of(body);
enrichedBody["token"] = emailChangeToken;
enrichedBody["password"] = userPassword;
return client
.send(
"$baseCollectionPath/confirm-email-change",
method: "POST",
body: enrichedBody,
query: query,
headers: headers,
)
.then((item) {
final parts = emailChangeToken.split(".");
if (parts.length != 3) {
return;
}
final payloadPart = base64.normalize(parts[1]);
final payload = jsonDecode(utf8.decode(base64Decode(payloadPart)))
as Map<String, dynamic>;
if (client.authStore.record != null &&
client.authStore.record?.id == payload["id"] &&
client.authStore.record?.collectionId == payload["collectionId"]) {
client.authStore.clear();
}
});
}