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(nhost_flutter_auth): Allow displayName and locale to be passed on signInAnonymous #131

Merged
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
31 changes: 27 additions & 4 deletions packages/nhost_auth_dart/lib/src/auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,34 @@ class NhostAuthClient implements HasuraAuthClient {
/// Nhost dashboard -> settings -> Sign in methods -> Anonymous Users
/// Throws an [NhostException] if sign in fails.
@override
Future<void> signInAnonymous() async {
Future<void> signInAnonymous(
String? displayName,
String? locale,
Map<String, dynamic>? metadata,
) async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind adding metadata too now that we are at it? Should just be an arbitrary map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata is ignored at the moment on nhost hasura_auth, so metadata will not be saved on user's side. but i added it just in case in the future hasura_auth will allow sending the metada for signing in anonymously.

@dbarrosop

log.finer('Attempting sign in anonymously');
await _apiClient.post(
'/signin/anonymous',
);

AuthResponse? res;
try {
res = await _apiClient.post(
'/signin/anonymous',
jsonBody: {
if (displayName != null) 'displayName': displayName,
if (locale != null) 'locale': locale,
if (metadata != null) 'metadata': metadata
},
responseDeserializer: AuthResponse.fromJson,
);
} catch (e, st) {
log.finer('Sign in anonymously failed', e, st);
await clearSession();
rethrow;
}

if (res != null) {
log.finer('Sign in anonymously successful');
await setSession(res.session!);
}
}

/// Authenticates a user using a [phoneNumber].
Expand Down
6 changes: 5 additions & 1 deletion packages/nhost_sdk/lib/src/base/hasura_auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ abstract class HasuraAuthClient {
String? redirectTo,
});

Future<void> signInAnonymous();
Future<void> signInAnonymous(
String? displayName,
String? locale,
Map<String, dynamic>? metadata,
);
Future<void> signInWithSmsPasswordless({
required String phoneNumber,
String? locale,
Expand Down
Loading