Skip to content

Commit

Permalink
feat(nhost_flutter_auth): Add metadata to the request body and set se…
Browse files Browse the repository at this point in the history
…ssion after signing in anonymously
  • Loading branch information
sl1mpshady committed Feb 5, 2024
1 parent 77010bf commit 572ebdf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/nhost_auth_dart/lib/src/auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,31 @@ class NhostAuthClient implements HasuraAuthClient {
Future<void> signInAnonymous(
String? displayName,
String? locale,
Map<String, dynamic>? metadata,
) async {
log.finer('Attempting sign in anonymously');
await _apiClient.post(
'/signin/anonymous',
jsonBody: {
if (displayName != null) 'displayName': displayName,
if (locale != null) 'locale': locale,
},
);

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
1 change: 1 addition & 0 deletions packages/nhost_sdk/lib/src/base/hasura_auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ abstract class HasuraAuthClient {
Future<void> signInAnonymous(
String? displayName,
String? locale,
Map<String, dynamic>? metadata,
);
Future<void> signInWithSmsPasswordless({
required String phoneNumber,
Expand Down

0 comments on commit 572ebdf

Please sign in to comment.