Skip to content

Commit 90e5fb2

Browse files
feat: Allow metadata to be passed in signInWithEmailPasswordless (#162)
* feat: Allow metadata to be passed in signInWithEmailPasswordless * fix: signInIdToken updated to openapi spec of hasura-auth --------- Co-authored-by: David Barroso <dbarrosop@dravetech.com>
1 parent 541c8da commit 90e5fb2

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

packages/nhost_auth_dart/lib/src/auth_client.dart

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,24 @@ class NhostAuthClient implements HasuraAuthClient {
291291
log.finer('Attempting sign in (idToken)');
292292
AuthResponse? res;
293293

294+
final includeRoleOptions = defaultRole != null || (roles != null && roles.isNotEmpty);
295+
final options = {
296+
if (metadata != null) 'metadata': metadata,
297+
if (locale != null) 'locale': locale,
298+
if (includeRoleOptions) 'defaultRole': defaultRole,
299+
if (includeRoleOptions) 'allowedRoles': roles,
300+
if (displayName != null) 'displayName': displayName,
301+
if (redirectTo != null) 'redirectTo': redirectTo,
302+
};
303+
294304
try {
295305
res = await _apiClient.post(
296306
'/signin/idtoken',
297307
jsonBody: {
298308
'provider': provider,
299309
'idToken': idToken,
300310
if (nonce != null) 'nonce': nonce,
301-
if (locale != null) 'locale': locale,
302-
if (defaultRole != null) 'defaultRole': defaultRole,
303-
if (metadata != null) 'metadata': metadata,
304-
if (roles != null) 'roles': roles,
305-
if (displayName != null) 'displayName': displayName,
306-
if (redirectTo != null) 'redirectTo': redirectTo,
311+
if (options.isNotEmpty) 'options': options
307312
},
308313
responseDeserializer: AuthResponse.fromJson,
309314
);
@@ -356,19 +361,32 @@ class NhostAuthClient implements HasuraAuthClient {
356361
///
357362
/// Throws an [NhostException] if sign in fails.
358363
@override
359-
Future<void> signInWithEmailPasswordless(
360-
String email, {
364+
Future<void> signInWithEmailPasswordless({
365+
required String email,
366+
String? locale,
367+
String? defaultRole,
368+
Map<String, Object?>? metadata,
369+
List<String>? roles,
370+
String? displayName,
361371
String? redirectTo,
362372
}) async {
363373
log.finer('Attempting sign in (passwordless email)');
374+
375+
final includeRoleOptions = defaultRole != null || (roles != null && roles.isNotEmpty);
376+
final options = {
377+
if (metadata != null) 'metadata': metadata,
378+
if (locale != null) 'locale': locale,
379+
if (includeRoleOptions) 'defaultRole': defaultRole,
380+
if (includeRoleOptions) 'allowedRoles': roles,
381+
if (displayName != null) 'displayName': displayName,
382+
if (redirectTo != null) 'redirectTo': redirectTo,
383+
};
384+
364385
return _apiClient.post(
365386
'/signin/passwordless/email',
366387
jsonBody: {
367388
'email': email,
368-
if (redirectTo != null)
369-
'options': {
370-
'redirectTo': redirectTo,
371-
},
389+
if (options.isNotEmpty) 'options': options,
372390
},
373391
);
374392
}

packages/nhost_sdk/lib/src/base/hasura_auth_client.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ abstract class HasuraAuthClient {
4444
Future<void> linkIdToken(
4545
{required String provider, required String idToken, String? nonce});
4646

47-
Future<void> signInWithEmailPasswordless(
48-
String email, {
47+
Future<void> signInWithEmailPasswordless({
48+
required String email,
49+
String? locale,
50+
String? defaultRole,
51+
Map<String, Object?>? metadata,
52+
List<String>? roles,
53+
String? displayName,
4954
String? redirectTo,
5055
});
5156

0 commit comments

Comments
 (0)