Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Cloudflare Turnstile response param in signUp (#155) #156

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading