@@ -26,6 +26,7 @@ class GoTrueApi {
26
26
String password, {
27
27
AuthOptions ? options,
28
28
Map <String , dynamic >? userMetadata,
29
+ String ? captchaToken,
29
30
}) async {
30
31
final urlParams = [];
31
32
@@ -41,6 +42,7 @@ class GoTrueApi {
41
42
'email' : email,
42
43
'password' : password,
43
44
'data' : userMetadata,
45
+ 'gotrue_meta_security' : {'hcaptcha_token' : captchaToken},
44
46
},
45
47
options: FetchOptions (headers),
46
48
);
@@ -100,12 +102,14 @@ class GoTrueApi {
100
102
String phone,
101
103
String password, {
102
104
Map <String , dynamic >? userMetadata,
105
+ String ? captchaToken,
103
106
}) async {
104
107
final fetchOptions = FetchOptions (headers);
105
108
final body = {
106
109
'phone' : phone,
107
110
'password' : password,
108
111
'data' : userMetadata,
112
+ 'gotrue_meta_security' : {'hcaptcha_token' : captchaToken},
109
113
};
110
114
final response =
111
115
await _fetch.post ('$url /signup' , body, options: fetchOptions);
@@ -140,13 +144,11 @@ class GoTrueApi {
140
144
String phone, [
141
145
String ? password,
142
146
]) async {
143
- final body = {'phone' : phone, 'password' : password};
144
- final fetchOptions = FetchOptions (headers);
145
147
const queryString = '?grant_type=password' ;
146
148
final response = await _fetch.post (
147
149
'$url /token$queryString ' ,
148
- body ,
149
- options: fetchOptions ,
150
+ { 'phone' : phone, 'password' : password} ,
151
+ options: FetchOptions (headers) ,
150
152
);
151
153
final session = Session .fromJson (response.rawData as Map <String , dynamic >);
152
154
return GotrueSessionResponse .fromResponse (
@@ -163,7 +165,7 @@ class GoTrueApi {
163
165
'id_token' : oidc.idToken,
164
166
'nonce' : oidc.nonce,
165
167
'client_id' : oidc.clientId,
166
- " issuer" : oidc.issuer,
168
+ ' issuer' : oidc.issuer,
167
169
'provider' : oidc.provider? .name (),
168
170
};
169
171
final fetchOptions = FetchOptions (headers);
@@ -184,8 +186,9 @@ class GoTrueApi {
184
186
Future <GotrueJsonResponse > sendMagicLinkEmail (
185
187
String email, {
186
188
AuthOptions ? options,
189
+ bool ? shouldCreateUser,
190
+ String ? captchaToken,
187
191
}) async {
188
- final body = {'email' : email};
189
192
final fetchOptions = FetchOptions (headers);
190
193
final urlParams = [];
191
194
if (options? .redirectTo != null ) {
@@ -194,8 +197,12 @@ class GoTrueApi {
194
197
}
195
198
final queryString = urlParams.isNotEmpty ? '?${urlParams .join ('&' )}' : '' ;
196
199
final response = await _fetch.post (
197
- '$url /magiclink$queryString ' ,
198
- body,
200
+ '$url /otp$queryString ' ,
201
+ {
202
+ 'email' : email,
203
+ 'create_user' : shouldCreateUser,
204
+ 'gotrue_meta_security' : {'hcaptcha_token' : captchaToken},
205
+ },
199
206
options: fetchOptions,
200
207
);
201
208
return GotrueJsonResponse .fromResponse (
@@ -207,8 +214,16 @@ class GoTrueApi {
207
214
/// Sends a mobile OTP via SMS. Will register the account if it doesn't already exist
208
215
///
209
216
/// [phone] is the user's phone number WITH international prefix
210
- Future <GotrueJsonResponse > sendMobileOTP (String phone) async {
211
- final body = {'phone' : phone};
217
+ Future <GotrueJsonResponse > sendMobileOTP (
218
+ String phone, {
219
+ bool ? shouldCreateUser,
220
+ String ? captchaToken,
221
+ }) async {
222
+ final body = {
223
+ 'phone' : phone,
224
+ 'create_user' : shouldCreateUser,
225
+ 'gotrue_meta_security' : {'hcaptcha_token' : captchaToken},
226
+ };
212
227
final fetchOptions = FetchOptions (headers);
213
228
final response = await _fetch.post ('$url /otp' , body, options: fetchOptions);
214
229
return GotrueJsonResponse .fromResponse (
@@ -222,6 +237,7 @@ class GoTrueApi {
222
237
/// [phone] is the user's phone number WITH international prefix
223
238
///
224
239
/// [token] is the token that user was sent to their mobile phone
240
+ @Deprecated ('Use verifyOTP instead' )
225
241
Future <GotrueSessionResponse > verifyMobileOTP (
226
242
String phone,
227
243
String token, {
@@ -280,8 +296,12 @@ class GoTrueApi {
280
296
Future <GotrueJsonResponse > resetPasswordForEmail (
281
297
String email, {
282
298
AuthOptions ? options,
299
+ String ? captchaToken,
283
300
}) async {
284
- final body = {'email' : email};
301
+ final body = {
302
+ 'email' : email,
303
+ 'gotrue_meta_security' : {'hcaptcha_token' : captchaToken},
304
+ };
285
305
final fetchOptions = FetchOptions (headers);
286
306
final urlParams = [];
287
307
if (options? .redirectTo != null ) {
@@ -363,14 +383,4 @@ class GoTrueApi {
363
383
data: session,
364
384
);
365
385
}
366
-
367
- // TODO: not implemented yet
368
- Never setAuthCookie () {
369
- throw UnimplementedError ();
370
- }
371
-
372
- // TODO: not implemented yet
373
- Never getUserByCookie () {
374
- throw UnimplementedError ();
375
- }
376
386
}
0 commit comments