@@ -41,7 +41,7 @@ public Api(string url, Dictionary<string, string> headers)
41
41
/// <param name="password"></param>
42
42
/// <param name="options">Optional Signup data.</param>
43
43
/// <returns></returns>
44
- public async Task < Session > SignUpWithEmail ( string email , string password , SignUpOptions options = null )
44
+ public async Task < Session ? > SignUpWithEmail ( string email , string password , SignUpOptions ? options = null )
45
45
{
46
46
var body = new Dictionary < string , object > { { "email" , email } , { "password" , password } } ;
47
47
@@ -51,7 +51,7 @@ public async Task<Session> SignUpWithEmail(string email, string password, SignUp
51
51
{
52
52
if ( ! string . IsNullOrEmpty ( options . RedirectTo ) )
53
53
{
54
- endpoint = Helpers . AddQueryParams ( endpoint , new Dictionary < string , string > { { "redirect_to" , options . RedirectTo } } ) . ToString ( ) ;
54
+ endpoint = Helpers . AddQueryParams ( endpoint , new Dictionary < string , string > { { "redirect_to" , options . RedirectTo ! } } ) . ToString ( ) ;
55
55
}
56
56
57
57
if ( options . Data != null )
@@ -62,18 +62,25 @@ public async Task<Session> SignUpWithEmail(string email, string password, SignUp
62
62
63
63
var response = await Helpers . MakeRequest ( HttpMethod . Post , endpoint , body , Headers ) ;
64
64
65
- // Gotrue returns a Session object for an auto-/pre-confirmed account
66
- var session = JsonConvert . DeserializeObject < Session > ( response . Content ) ;
65
+ if ( ! string . IsNullOrEmpty ( response . Content ) )
66
+ {
67
+ // Gotrue returns a Session object for an auto-/pre-confirmed account
68
+ var session = JsonConvert . DeserializeObject < Session > ( response . Content ! ) ;
67
69
68
- // If account is unconfirmed, Gotrue returned the user object, so fill User data
69
- // in from the parsed response.
70
- if ( session . User == null )
70
+ // If account is unconfirmed, Gotrue returned the user object, so fill User data
71
+ // in from the parsed response.
72
+ if ( session != null && session . User == null )
73
+ {
74
+ // Gotrue returns a User object for an unconfirmed account
75
+ session . User = JsonConvert . DeserializeObject < User > ( response . Content ! ) ;
76
+ }
77
+
78
+ return session ;
79
+ }
80
+ else
71
81
{
72
- // Gotrue returns a User object for an unconfirmed account
73
- session . User = JsonConvert . DeserializeObject < User > ( response . Content ) ;
82
+ return null ;
74
83
}
75
-
76
- return session ;
77
84
}
78
85
79
86
/// <summary>
@@ -82,7 +89,7 @@ public async Task<Session> SignUpWithEmail(string email, string password, SignUp
82
89
/// <param name="email"></param>
83
90
/// <param name="password"></param>
84
91
/// <returns></returns>
85
- public Task < Session > SignInWithEmail ( string email , string password )
92
+ public Task < Session ? > SignInWithEmail ( string email , string password )
86
93
{
87
94
var body = new Dictionary < string , object > { { "email" , email } , { "password" , password } } ;
88
95
return Helpers . MakeRequest < Session > ( HttpMethod . Post , $ "{ Url } /token?grant_type=password", body , Headers ) ;
@@ -94,7 +101,7 @@ public Task<Session> SignInWithEmail(string email, string password)
94
101
/// <param name="email"></param>
95
102
/// <param name="options"></param>
96
103
/// <returns></returns>
97
- public Task < BaseResponse > SendMagicLinkEmail ( string email , SignInOptions options = null )
104
+ public Task < BaseResponse > SendMagicLinkEmail ( string email , SignInOptions ? options = null )
98
105
{
99
106
var data = new Dictionary < string , string > { { "email" , email } } ;
100
107
@@ -104,7 +111,7 @@ public Task<BaseResponse> SendMagicLinkEmail(string email, SignInOptions options
104
111
{
105
112
if ( ! string . IsNullOrEmpty ( options . RedirectTo ) )
106
113
{
107
- endpoint = Helpers . AddQueryParams ( endpoint , new Dictionary < string , string > { { "redirect_to" , options . RedirectTo } } ) . ToString ( ) ;
114
+ endpoint = Helpers . AddQueryParams ( endpoint , new Dictionary < string , string > { { "redirect_to" , options . RedirectTo ! } } ) . ToString ( ) ;
108
115
}
109
116
}
110
117
@@ -130,7 +137,7 @@ public Task<BaseResponse> InviteUserByEmail(string email, string jwt)
130
137
/// <param name="password">The password of the user.</param>
131
138
/// <param name="options">Optional Signup data.</param>
132
139
/// <returns></returns>
133
- public Task < Session > SignUpWithPhone ( string phone , string password , SignUpOptions options = null )
140
+ public Task < Session ? > SignUpWithPhone ( string phone , string password , SignUpOptions ? options = null )
134
141
{
135
142
var body = new Dictionary < string , object > {
136
143
{ "phone" , phone } ,
@@ -143,7 +150,7 @@ public Task<Session> SignUpWithPhone(string phone, string password, SignUpOption
143
150
{
144
151
if ( ! string . IsNullOrEmpty ( options . RedirectTo ) )
145
152
{
146
- endpoint = Helpers . AddQueryParams ( endpoint , new Dictionary < string , string > { { "redirect_to" , options . RedirectTo } } ) . ToString ( ) ;
153
+ endpoint = Helpers . AddQueryParams ( endpoint , new Dictionary < string , string > { { "redirect_to" , options . RedirectTo ! } } ) . ToString ( ) ;
147
154
}
148
155
149
156
if ( options . Data != null )
@@ -161,7 +168,7 @@ public Task<Session> SignUpWithPhone(string phone, string password, SignUpOption
161
168
/// <param name="phone">The phone number of the user.</param>
162
169
/// <param name="password">The password of the user.</param>
163
170
/// <returns></returns>
164
- public Task < Session > SignInWithPhone ( string phone , string password )
171
+ public Task < Session ? > SignInWithPhone ( string phone , string password )
165
172
{
166
173
var data = new Dictionary < string , object > {
167
174
{ "phone" , phone } ,
@@ -187,7 +194,7 @@ public Task<BaseResponse> SendMobileOTP(string phone)
187
194
/// <param name="phone">The user's phone number WITH international prefix</param>
188
195
/// <param name="token">token that user was sent to their mobile phone</param>
189
196
/// <returns></returns>
190
- public Task < Session > VerifyMobileOTP ( string phone , string token , MobileOtpType type )
197
+ public Task < Session ? > VerifyMobileOTP ( string phone , string token , MobileOtpType type )
191
198
{
192
199
var data = new Dictionary < string , string > {
193
200
{ "phone" , phone } ,
@@ -203,7 +210,7 @@ public Task<Session> VerifyMobileOTP(string phone, string token, MobileOtpType t
203
210
/// <param name="phone">The user's phone number WITH international prefix</param>
204
211
/// <param name="token">token that user was sent to their mobile phone</param>
205
212
/// <returns></returns>
206
- public Task < Session > VerifyEmailOTP ( string email , string token , EmailOtpType type )
213
+ public Task < Session ? > VerifyEmailOTP ( string email , string token , EmailOtpType type )
207
214
{
208
215
var data = new Dictionary < string , string > {
209
216
{ "email" , email } ,
@@ -244,7 +251,7 @@ internal Dictionary<string, string> CreateAuthedRequestHeaders(string jwt)
244
251
/// <param name="provider"></param>
245
252
/// <param name="scopes">A space-separated list of scopes granted to the OAuth application.</param>
246
253
/// <returns></returns>
247
- public string GetUrlForProvider ( Provider provider , string scopes = null )
254
+ public string GetUrlForProvider ( Provider provider , string ? scopes = null )
248
255
{
249
256
var builder = new UriBuilder ( $ "{ Url } /authorize") ;
250
257
var attr = Helpers . GetMappedToAttr ( provider ) ;
@@ -279,7 +286,7 @@ public Task<BaseResponse> SignOut(string jwt)
279
286
/// </summary>
280
287
/// <param name="jwt"></param>
281
288
/// <returns></returns>
282
- public Task < User > GetUser ( string jwt )
289
+ public Task < User ? > GetUser ( string jwt )
283
290
{
284
291
var data = new Dictionary < string , string > { } ;
285
292
@@ -292,7 +299,7 @@ public Task<User> GetUser(string jwt)
292
299
/// <param name="jwt">A valid JWT. Must be a full-access API key (e.g. service_role key).</param>
293
300
/// <param name="userId"></param>
294
301
/// <returns></returns>
295
- public Task < User > GetUserById ( string jwt , string userId )
302
+ public Task < User ? > GetUserById ( string jwt , string userId )
296
303
{
297
304
var data = new Dictionary < string , string > { } ;
298
305
@@ -305,7 +312,7 @@ public Task<User> GetUserById(string jwt, string userId)
305
312
/// <param name="jwt"></param>
306
313
/// <param name="attributes"></param>
307
314
/// <returns></returns>
308
- public Task < User > UpdateUser ( string jwt , UserAttributes attributes )
315
+ public Task < User ? > UpdateUser ( string jwt , UserAttributes attributes )
309
316
{
310
317
return Helpers . MakeRequest < User > ( HttpMethod . Put , $ "{ Url } /user", attributes , CreateAuthedRequestHeaders ( jwt ) ) ;
311
318
}
@@ -320,18 +327,18 @@ public Task<User> UpdateUser(string jwt, UserAttributes attributes)
320
327
/// <param name="page">page to show for pagination</param>
321
328
/// <param name="perPage">items per page for pagination</param>
322
329
/// <returns></returns>
323
- public Task < UserList < User > > ListUsers ( string jwt , string filter = null , string sortBy = null , SortOrder sortOrder = SortOrder . Descending , int ? page = null , int ? perPage = null )
330
+ public Task < UserList < User > ? > ListUsers ( string jwt , string ? filter = null , string ? sortBy = null , SortOrder sortOrder = SortOrder . Descending , int ? page = null , int ? perPage = null )
324
331
{
325
332
var data = TransformListUsersParams ( filter , sortBy , sortOrder , page , perPage ) ;
326
333
327
334
return Helpers . MakeRequest < UserList < User > > ( HttpMethod . Get , $ "{ Url } /admin/users", data , CreateAuthedRequestHeaders ( jwt ) ) ;
328
335
}
329
336
330
- internal Dictionary < string , string > TransformListUsersParams ( string filter = null , string sortBy = null , SortOrder sortOrder = SortOrder . Descending , int ? page = null , int ? perPage = null )
337
+ internal Dictionary < string , string > TransformListUsersParams ( string ? filter = null , string ? sortBy = null , SortOrder sortOrder = SortOrder . Descending , int ? page = null , int ? perPage = null )
331
338
{
332
339
var query = new Dictionary < string , string > { } ;
333
340
334
- if ( ! string . IsNullOrWhiteSpace ( filter ) )
341
+ if ( filter != null && ! string . IsNullOrWhiteSpace ( filter ) )
335
342
{
336
343
query . Add ( "filter" , filter ) ;
337
344
}
@@ -363,8 +370,13 @@ internal Dictionary<string, string> TransformListUsersParams(string filter = nul
363
370
/// <param name="password"></param>
364
371
/// <param name="userData"></param>
365
372
/// <returns></returns>
366
- public Task < User > CreateUser ( string jwt , AdminUserAttributes attributes = null )
373
+ public Task < User ? > CreateUser ( string jwt , AdminUserAttributes ? attributes = null )
367
374
{
375
+ if ( attributes == null )
376
+ {
377
+ attributes = new AdminUserAttributes ( ) ;
378
+ }
379
+
368
380
return Helpers . MakeRequest < User > ( HttpMethod . Post , $ "{ Url } /admin/users", attributes , CreateAuthedRequestHeaders ( jwt ) ) ;
369
381
}
370
382
@@ -375,7 +387,7 @@ public Task<User> CreateUser(string jwt, AdminUserAttributes attributes = null)
375
387
/// <param name="userId"></param>
376
388
/// <param name="data"></param>
377
389
/// <returns></returns>
378
- public Task < User > UpdateUserById ( string jwt , string userId , UserAttributes userData )
390
+ public Task < User ? > UpdateUserById ( string jwt , string userId , UserAttributes userData )
379
391
{
380
392
return Helpers . MakeRequest < User > ( HttpMethod . Put , $ "{ Url } /admin/users/{ userId } ", userData , CreateAuthedRequestHeaders ( jwt ) ) ;
381
393
}
@@ -397,7 +409,7 @@ public Task<BaseResponse> DeleteUser(string uid, string jwt)
397
409
/// </summary>
398
410
/// <param name="refreshToken"></param>
399
411
/// <returns></returns>
400
- public Task < Session > RefreshAccessToken ( string refreshToken )
412
+ public Task < Session ? > RefreshAccessToken ( string refreshToken )
401
413
{
402
414
var data = new Dictionary < string , string > {
403
415
{ "refresh_token" , refreshToken }
@@ -415,7 +427,7 @@ public class SignUpOptions : SignInOptions
415
427
/// <summary>
416
428
/// Optional user metadata.
417
429
/// </summary>
418
- public Dictionary < string , object > Data { get ; set ; }
430
+ public Dictionary < string , object > ? Data { get ; set ; }
419
431
}
420
432
421
433
// <summary>
@@ -426,6 +438,6 @@ public class SignInOptions
426
438
/// <summary>
427
439
/// A URL or mobile address to send the user to after they are confirmed.
428
440
/// </summary>
429
- public string RedirectTo { get ; set ; }
441
+ public string ? RedirectTo { get ; set ; }
430
442
}
431
443
}
0 commit comments