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
wildsurfer authored Dec 13, 2024
1 parent 5fa2f64 commit e636019
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/test.nhost_auth_dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ on:
# Run the quality job at 4am every day
# - cron: '0 4 * * *'

env: {}
env:
MAX_PANA_MISSING_POINTS: 40
jobs:
# Ensure that the package meets a suitably high pub.dev score
score-package-quality:
Expand Down
7 changes: 7 additions & 0 deletions 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 Down

0 comments on commit e636019

Please sign in to comment.