@@ -26,9 +26,10 @@ namespace FirebaseAdmin.Auth
26
26
/// </summary>
27
27
public sealed class UserRecordArgs
28
28
{
29
- private static readonly object Unspecified = new object ( ) ;
30
-
31
- private object customClaims = Unspecified ;
29
+ private Optional < string > displayName ;
30
+ private Optional < string > photoUrl ;
31
+ private Optional < string > phoneNumber ;
32
+ private Optional < IReadOnlyDictionary < string , object > > customClaims ;
32
33
private bool ? disabled = null ;
33
34
private bool ? emailVerified = null ;
34
35
@@ -45,12 +46,20 @@ public sealed class UserRecordArgs
45
46
/// <summary>
46
47
/// Gets or sets the phone number of the user.
47
48
/// </summary>
48
- public string PhoneNumber { get ; set ; }
49
+ public string PhoneNumber
50
+ {
51
+ get => this . phoneNumber ? . Value ;
52
+ set => this . phoneNumber = this . Wrap ( value ) ;
53
+ }
49
54
50
55
/// <summary>
51
56
/// Gets or sets the display name of the user account.
52
57
/// </summary>
53
- public string DisplayName { get ; set ; }
58
+ public string DisplayName
59
+ {
60
+ get => this . displayName ? . Value ;
61
+ set => this . displayName = this . Wrap ( value ) ;
62
+ }
54
63
55
64
/// <summary>
56
65
/// Gets or sets a value indicating whether the user email address has been verified or not.
@@ -64,7 +73,11 @@ public bool EmailVerified
64
73
/// <summary>
65
74
/// Gets or sets the photo URL of the user.
66
75
/// </summary>
67
- public string PhotoUrl { get ; set ; }
76
+ public string PhotoUrl
77
+ {
78
+ get => this . photoUrl ? . Value ;
79
+ set => this . photoUrl = this . Wrap ( value ) ;
80
+ }
68
81
69
82
/// <summary>
70
83
/// Gets or sets a value indicating whether the user account should be disabled by default or not.
@@ -82,8 +95,8 @@ public bool Disabled
82
95
83
96
internal IReadOnlyDictionary < string , object > CustomClaims
84
97
{
85
- get => this . GetIfSpecified < Dictionary < string , object > > ( this . customClaims ) ;
86
- set => this . customClaims = value ;
98
+ get => this . customClaims ? . Value ;
99
+ set => this . customClaims = this . Wrap ( value ) ;
87
100
}
88
101
89
102
internal CreateUserRequest ToCreateUserRequest ( )
@@ -212,14 +225,9 @@ private static string CheckCustomClaims(IReadOnlyDictionary<string, object> clai
212
225
return customClaimsString ;
213
226
}
214
227
215
- private T GetIfSpecified < T > ( object value )
228
+ private Optional < T > Wrap < T > ( T value )
216
229
{
217
- if ( value == Unspecified )
218
- {
219
- return default ( T ) ;
220
- }
221
-
222
- return ( T ) value ;
230
+ return new Optional < T > ( value ) ;
223
231
}
224
232
225
233
internal sealed class CreateUserRequest
@@ -266,17 +274,118 @@ internal sealed class UpdateUserRequest
266
274
internal UpdateUserRequest ( UserRecordArgs args )
267
275
{
268
276
this . Uid = CheckUid ( args . Uid , required : true ) ;
269
- if ( args . customClaims != Unspecified )
277
+ if ( args . customClaims != null )
278
+ {
279
+ this . CustomClaims = CheckCustomClaims ( args . customClaims . Value ) ;
280
+ }
281
+
282
+ this . Disabled = args . disabled ;
283
+ this . Email = CheckEmail ( args . Email ) ;
284
+ this . EmailVerified = args . emailVerified ;
285
+ this . Password = CheckPassword ( args . Password ) ;
286
+
287
+ if ( args . displayName != null )
270
288
{
271
- this . CustomClaims = CheckCustomClaims ( args . CustomClaims ) ;
289
+ var displayName = args . displayName . Value ;
290
+ if ( displayName == null )
291
+ {
292
+ this . AddDeleteAttribute ( "DISPLAY_NAME" ) ;
293
+ }
294
+ else
295
+ {
296
+ this . DisplayName = displayName ;
297
+ }
298
+ }
299
+
300
+ if ( args . photoUrl != null )
301
+ {
302
+ var photoUrl = args . photoUrl . Value ;
303
+ if ( photoUrl == null )
304
+ {
305
+ this . AddDeleteAttribute ( "PHOTO_URL" ) ;
306
+ }
307
+ else
308
+ {
309
+ this . PhotoUrl = CheckPhotoUrl ( photoUrl ) ;
310
+ }
311
+ }
312
+
313
+ if ( args . phoneNumber != null )
314
+ {
315
+ var phoneNumber = args . phoneNumber . Value ;
316
+ if ( phoneNumber == null )
317
+ {
318
+ this . AddDeleteProvider ( "phone" ) ;
319
+ }
320
+ else
321
+ {
322
+ this . PhoneNumber = CheckPhoneNumber ( phoneNumber ) ;
323
+ }
272
324
}
273
325
}
274
326
327
+ [ JsonProperty ( "customAttributes" ) ]
328
+ public string CustomClaims { get ; set ; }
329
+
330
+ [ JsonProperty ( "deleteAttribute" ) ]
331
+ public IList < string > DeleteAttribute { get ; set ; }
332
+
333
+ [ JsonProperty ( "deleteProvider" ) ]
334
+ public IList < string > DeleteProvider { get ; set ; }
335
+
336
+ [ JsonProperty ( "disableUser" ) ]
337
+ public bool ? Disabled { get ; set ; }
338
+
339
+ [ JsonProperty ( "displayName" ) ]
340
+ public string DisplayName { get ; set ; }
341
+
342
+ [ JsonProperty ( "email" ) ]
343
+ public string Email { get ; set ; }
344
+
345
+ [ JsonProperty ( "emailVerified" ) ]
346
+ public bool ? EmailVerified { get ; set ; }
347
+
348
+ [ JsonProperty ( "password" ) ]
349
+ public string Password { get ; set ; }
350
+
351
+ [ JsonProperty ( "phoneNumber" ) ]
352
+ public string PhoneNumber { get ; set ; }
353
+
354
+ [ JsonProperty ( "photoUrl" ) ]
355
+ public string PhotoUrl { get ; set ; }
356
+
275
357
[ JsonProperty ( "localId" ) ]
276
358
public string Uid { get ; set ; }
277
359
278
- [ JsonProperty ( "customAttributes" ) ]
279
- public string CustomClaims { get ; set ; }
360
+ private void AddDeleteAttribute ( string attribute )
361
+ {
362
+ if ( this . DeleteAttribute == null )
363
+ {
364
+ this . DeleteAttribute = new List < string > ( ) ;
365
+ }
366
+
367
+ this . DeleteAttribute . Add ( attribute ) ;
368
+ }
369
+
370
+ private void AddDeleteProvider ( string provider )
371
+ {
372
+ if ( this . DeleteProvider == null )
373
+ {
374
+ this . DeleteProvider = new List < string > ( ) ;
375
+ }
376
+
377
+ this . DeleteProvider . Add ( provider ) ;
378
+ }
379
+ }
380
+
381
+ internal class Optional < T >
382
+ {
383
+ internal Optional ( T value )
384
+ {
385
+ this . Value = value ;
386
+ }
387
+
388
+ internal T Value { get ; private set ; }
280
389
}
281
390
}
282
391
}
0 commit comments