Skip to content

Commit

Permalink
feat: add support for Cloudflare Turnstile response param in signUp (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kuznetsov committed Dec 7, 2024
1 parent 5fa2f64 commit 17e78fb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/nhost_auth_dart/lib/src/auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthResponse> signUp({
Expand All @@ -182,9 +185,12 @@ class NhostAuthClient implements HasuraAuthClient {
List<String>? 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 = {
Expand All @@ -205,6 +211,7 @@ class NhostAuthClient implements HasuraAuthClient {
if (options.isNotEmpty) 'options': options,
},
responseDeserializer: AuthResponse.fromJson,
headers: headers,
);
log.finer('Registration successful');

Expand All @@ -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
Expand Down

0 comments on commit 17e78fb

Please sign in to comment.