From 17e78fb27febfc2cb32d79785842aa63ec8e5a5a Mon Sep 17 00:00:00 2001 From: Ivan Kuznetsov Date: Sat, 7 Dec 2024 17:09:55 +0000 Subject: [PATCH] feat: add support for Cloudflare Turnstile response param in signUp (#155) --- packages/nhost_auth_dart/lib/src/auth_client.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/nhost_auth_dart/lib/src/auth_client.dart b/packages/nhost_auth_dart/lib/src/auth_client.dart index a621324e..f5ae1e63 100644 --- a/packages/nhost_auth_dart/lib/src/auth_client.dart +++ b/packages/nhost_auth_dart/lib/src/auth_client.dart @@ -171,6 +171,9 @@ class NhostAuthClient implements HasuraAuthClient { /// returned [AuthResponse] will not contain a session. The user must first /// activate their account by clicking an activation link sent to their email. /// + /// If [turnstileResponse] is provided, it will be included in the request headers + /// as `x-cf-turnstile-response` to support Cloudflare Turnstile protection. + /// /// Throws an [NhostException] if registration fails. @override Future signUp({ @@ -182,9 +185,12 @@ class NhostAuthClient implements HasuraAuthClient { List? roles, String? displayName, String? redirectTo, + String? turnstileResponse, }) async { log.finer('Attempting user registration'); + final headers = + turnstileResponse != null ? {'x-cf-turnstile-response': turnstileResponse} : null; final includeRoleOptions = defaultRole != null || (roles != null && roles.isNotEmpty); final options = { @@ -205,6 +211,7 @@ class NhostAuthClient implements HasuraAuthClient { if (options.isNotEmpty) 'options': options, }, responseDeserializer: AuthResponse.fromJson, + headers: headers, ); log.finer('Registration successful'); @@ -220,7 +227,6 @@ class NhostAuthClient implements HasuraAuthClient { rethrow; } } - /// Authenticates a user using an [email] and [password]. /// /// If the user has multi-factor authentication enabled, the returned