confirmVerification method
Confirms auth record email verification request.
On success this method automatically updates the client's AuthStore.
Implementation
Future<void> confirmVerification(
String verificationToken, {
Map<String, dynamic> body = const {},
Map<String, dynamic> query = const {},
Map<String, String> headers = const {},
}) {
final enrichedBody = Map<String, dynamic>.of(body);
enrichedBody["token"] = verificationToken;
return client
.send(
"$baseCollectionPath/confirm-verification",
method: "POST",
body: enrichedBody,
query: query,
headers: headers,
)
.then((item) {
// on success manually update the current auth record verified state
final parts = verificationToken.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.model != null &&
client.authStore.model is RecordModel &&
!(client.authStore.model as RecordModel).getBoolValue("verified") &&
(client.authStore.model as RecordModel).id == payload["id"] &&
(client.authStore.model as RecordModel).collectionId ==
payload["collectionId"]) {
(client.authStore.model as RecordModel).data["verified"] = true;
client.authStore.save(client.authStore.token, client.authStore.model);
}
});
}