@@ -291,19 +291,24 @@ class NhostAuthClient implements HasuraAuthClient {
291
291
log.finer ('Attempting sign in (idToken)' );
292
292
AuthResponse ? res;
293
293
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
+
294
304
try {
295
305
res = await _apiClient.post (
296
306
'/signin/idtoken' ,
297
307
jsonBody: {
298
308
'provider' : provider,
299
309
'idToken' : idToken,
300
310
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
307
312
},
308
313
responseDeserializer: AuthResponse .fromJson,
309
314
);
@@ -356,19 +361,32 @@ class NhostAuthClient implements HasuraAuthClient {
356
361
///
357
362
/// Throws an [NhostException] if sign in fails.
358
363
@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,
361
371
String ? redirectTo,
362
372
}) async {
363
373
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
+
364
385
return _apiClient.post (
365
386
'/signin/passwordless/email' ,
366
387
jsonBody: {
367
388
'email' : email,
368
- if (redirectTo != null )
369
- 'options' : {
370
- 'redirectTo' : redirectTo,
371
- },
389
+ if (options.isNotEmpty) 'options' : options,
372
390
},
373
391
);
374
392
}
0 commit comments