@supabase/auth-js 2.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/dist/main/AuthAdminApi.d.ts +4 -0
  4. package/dist/main/AuthAdminApi.d.ts.map +1 -0
  5. package/dist/main/AuthAdminApi.js +9 -0
  6. package/dist/main/AuthAdminApi.js.map +1 -0
  7. package/dist/main/AuthClient.d.ts +4 -0
  8. package/dist/main/AuthClient.d.ts.map +1 -0
  9. package/dist/main/AuthClient.js +9 -0
  10. package/dist/main/AuthClient.js.map +1 -0
  11. package/dist/main/GoTrueAdminApi.d.ts +99 -0
  12. package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
  13. package/dist/main/GoTrueAdminApi.js +268 -0
  14. package/dist/main/GoTrueAdminApi.js.map +1 -0
  15. package/dist/main/GoTrueClient.d.ts +432 -0
  16. package/dist/main/GoTrueClient.d.ts.map +1 -0
  17. package/dist/main/GoTrueClient.js +1889 -0
  18. package/dist/main/GoTrueClient.js.map +1 -0
  19. package/dist/main/index.d.ts +9 -0
  20. package/dist/main/index.d.ts.map +1 -0
  21. package/dist/main/index.js +35 -0
  22. package/dist/main/index.js.map +1 -0
  23. package/dist/main/lib/constants.d.ts +12 -0
  24. package/dist/main/lib/constants.d.ts.map +1 -0
  25. package/dist/main/lib/constants.js +14 -0
  26. package/dist/main/lib/constants.js.map +1 -0
  27. package/dist/main/lib/errors.d.ts +96 -0
  28. package/dist/main/lib/errors.d.ts.map +1 -0
  29. package/dist/main/lib/errors.js +135 -0
  30. package/dist/main/lib/errors.js.map +1 -0
  31. package/dist/main/lib/fetch.d.ts +33 -0
  32. package/dist/main/lib/fetch.d.ts.map +1 -0
  33. package/dist/main/lib/fetch.js +162 -0
  34. package/dist/main/lib/fetch.js.map +1 -0
  35. package/dist/main/lib/helpers.d.ts +48 -0
  36. package/dist/main/lib/helpers.d.ts.map +1 -0
  37. package/dist/main/lib/helpers.js +292 -0
  38. package/dist/main/lib/helpers.js.map +1 -0
  39. package/dist/main/lib/local-storage.d.ts +13 -0
  40. package/dist/main/lib/local-storage.d.ts.map +1 -0
  41. package/dist/main/lib/local-storage.js +46 -0
  42. package/dist/main/lib/local-storage.js.map +1 -0
  43. package/dist/main/lib/locks.d.ts +44 -0
  44. package/dist/main/lib/locks.d.ts.map +1 -0
  45. package/dist/main/lib/locks.js +118 -0
  46. package/dist/main/lib/locks.js.map +1 -0
  47. package/dist/main/lib/polyfills.d.ts +5 -0
  48. package/dist/main/lib/polyfills.d.ts.map +1 -0
  49. package/dist/main/lib/polyfills.js +30 -0
  50. package/dist/main/lib/polyfills.js.map +1 -0
  51. package/dist/main/lib/types.d.ts +948 -0
  52. package/dist/main/lib/types.d.ts.map +1 -0
  53. package/dist/main/lib/types.js +3 -0
  54. package/dist/main/lib/types.js.map +1 -0
  55. package/dist/main/lib/version.d.ts +2 -0
  56. package/dist/main/lib/version.d.ts.map +1 -0
  57. package/dist/main/lib/version.js +6 -0
  58. package/dist/main/lib/version.js.map +1 -0
  59. package/dist/module/AuthAdminApi.d.ts +4 -0
  60. package/dist/module/AuthAdminApi.d.ts.map +1 -0
  61. package/dist/module/AuthAdminApi.js +4 -0
  62. package/dist/module/AuthAdminApi.js.map +1 -0
  63. package/dist/module/AuthClient.d.ts +4 -0
  64. package/dist/module/AuthClient.d.ts.map +1 -0
  65. package/dist/module/AuthClient.js +4 -0
  66. package/dist/module/AuthClient.js.map +1 -0
  67. package/dist/module/GoTrueAdminApi.d.ts +99 -0
  68. package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
  69. package/dist/module/GoTrueAdminApi.js +265 -0
  70. package/dist/module/GoTrueAdminApi.js.map +1 -0
  71. package/dist/module/GoTrueClient.d.ts +432 -0
  72. package/dist/module/GoTrueClient.d.ts.map +1 -0
  73. package/dist/module/GoTrueClient.js +1883 -0
  74. package/dist/module/GoTrueClient.js.map +1 -0
  75. package/dist/module/index.d.ts +9 -0
  76. package/dist/module/index.d.ts.map +1 -0
  77. package/dist/module/index.js +9 -0
  78. package/dist/module/index.js.map +1 -0
  79. package/dist/module/lib/constants.d.ts +12 -0
  80. package/dist/module/lib/constants.d.ts.map +1 -0
  81. package/dist/module/lib/constants.js +11 -0
  82. package/dist/module/lib/constants.js.map +1 -0
  83. package/dist/module/lib/errors.d.ts +96 -0
  84. package/dist/module/lib/errors.d.ts.map +1 -0
  85. package/dist/module/lib/errors.js +117 -0
  86. package/dist/module/lib/errors.js.map +1 -0
  87. package/dist/module/lib/fetch.d.ts +33 -0
  88. package/dist/module/lib/fetch.d.ts.map +1 -0
  89. package/dist/module/lib/fetch.js +152 -0
  90. package/dist/module/lib/fetch.js.map +1 -0
  91. package/dist/module/lib/helpers.d.ts +48 -0
  92. package/dist/module/lib/helpers.d.ts.map +1 -0
  93. package/dist/module/lib/helpers.js +249 -0
  94. package/dist/module/lib/helpers.js.map +1 -0
  95. package/dist/module/lib/local-storage.d.ts +13 -0
  96. package/dist/module/lib/local-storage.d.ts.map +1 -0
  97. package/dist/module/lib/local-storage.js +42 -0
  98. package/dist/module/lib/local-storage.js.map +1 -0
  99. package/dist/module/lib/locks.d.ts +44 -0
  100. package/dist/module/lib/locks.d.ts.map +1 -0
  101. package/dist/module/lib/locks.js +112 -0
  102. package/dist/module/lib/locks.js.map +1 -0
  103. package/dist/module/lib/polyfills.d.ts +5 -0
  104. package/dist/module/lib/polyfills.d.ts.map +1 -0
  105. package/dist/module/lib/polyfills.js +26 -0
  106. package/dist/module/lib/polyfills.js.map +1 -0
  107. package/dist/module/lib/types.d.ts +948 -0
  108. package/dist/module/lib/types.d.ts.map +1 -0
  109. package/dist/module/lib/types.js +2 -0
  110. package/dist/module/lib/types.js.map +1 -0
  111. package/dist/module/lib/version.d.ts +2 -0
  112. package/dist/module/lib/version.d.ts.map +1 -0
  113. package/dist/module/lib/version.js +3 -0
  114. package/dist/module/lib/version.js.map +1 -0
  115. package/package.json +69 -0
  116. package/src/AuthAdminApi.ts +5 -0
  117. package/src/AuthClient.ts +5 -0
  118. package/src/GoTrueAdminApi.ts +333 -0
  119. package/src/GoTrueClient.ts +2470 -0
  120. package/src/index.ts +12 -0
  121. package/src/lib/constants.ts +10 -0
  122. package/src/lib/errors.ts +150 -0
  123. package/src/lib/fetch.ts +238 -0
  124. package/src/lib/helpers.ts +306 -0
  125. package/src/lib/local-storage.ts +49 -0
  126. package/src/lib/locks.ts +140 -0
  127. package/src/lib/polyfills.ts +23 -0
  128. package/src/lib/types.ts +1120 -0
  129. package/src/lib/version.ts +2 -0
@@ -0,0 +1,948 @@
1
+ import { AuthError } from './errors';
2
+ import { Fetch } from './fetch';
3
+ /** One of the providers supported by GoTrue. */
4
+ export declare type Provider = 'apple' | 'azure' | 'bitbucket' | 'discord' | 'facebook' | 'figma' | 'github' | 'gitlab' | 'google' | 'kakao' | 'keycloak' | 'linkedin' | 'linkedin_oidc' | 'notion' | 'slack' | 'spotify' | 'twitch' | 'twitter' | 'workos' | 'zoom' | 'fly';
5
+ export declare type AuthChangeEventMFA = 'MFA_CHALLENGE_VERIFIED';
6
+ export declare type AuthChangeEvent = 'INITIAL_SESSION' | 'PASSWORD_RECOVERY' | 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED' | AuthChangeEventMFA;
7
+ /**
8
+ * Provide your own global lock implementation instead of the default
9
+ * implementation. The function should acquire a lock for the duration of the
10
+ * `fn` async function, such that no other client instances will be able to
11
+ * hold it at the same time.
12
+ *
13
+ * @experimental
14
+ *
15
+ * @param name Name of the lock to be acquired.
16
+ * @param acquireTimeout If negative, no timeout should occur. If positive it
17
+ * should throw an Error with an `isAcquireTimeout`
18
+ * property set to true if the operation fails to be
19
+ * acquired after this much time (ms).
20
+ * @param fn The operation to execute when the lock is acquired.
21
+ */
22
+ export declare type LockFunc = <R>(name: string, acquireTimeout: number, fn: () => Promise<R>) => Promise<R>;
23
+ export declare type GoTrueClientOptions = {
24
+ url?: string;
25
+ headers?: {
26
+ [key: string]: string;
27
+ };
28
+ storageKey?: string;
29
+ detectSessionInUrl?: boolean;
30
+ autoRefreshToken?: boolean;
31
+ persistSession?: boolean;
32
+ storage?: SupportedStorage;
33
+ fetch?: Fetch;
34
+ flowType?: AuthFlowType;
35
+ debug?: boolean | ((message: string, ...args: any[]) => void);
36
+ /**
37
+ * Provide your own locking mechanism based on the environment. By default no locking is done at this time.
38
+ *
39
+ * @experimental
40
+ */
41
+ lock?: LockFunc;
42
+ };
43
+ export declare type WeakPasswordReasons = 'length' | 'characters' | 'pwned' | string;
44
+ export declare type WeakPassword = {
45
+ reasons: WeakPasswordReasons[];
46
+ message: string;
47
+ };
48
+ export declare type AuthResponse = {
49
+ data: {
50
+ user: User | null;
51
+ session: Session | null;
52
+ };
53
+ error: null;
54
+ } | {
55
+ data: {
56
+ user: null;
57
+ session: null;
58
+ };
59
+ error: AuthError;
60
+ };
61
+ export declare type AuthResponsePassword = {
62
+ data: {
63
+ user: User | null;
64
+ session: Session | null;
65
+ weak_password?: WeakPassword | null;
66
+ };
67
+ error: null;
68
+ } | {
69
+ data: {
70
+ user: null;
71
+ session: null;
72
+ };
73
+ error: AuthError;
74
+ };
75
+ /**
76
+ * AuthOtpResponse is returned when OTP is used.
77
+ *
78
+ * {@see AuthRsponse}
79
+ */
80
+ export declare type AuthOtpResponse = {
81
+ data: {
82
+ user: null;
83
+ session: null;
84
+ messageId?: string | null;
85
+ };
86
+ error: null;
87
+ } | {
88
+ data: {
89
+ user: null;
90
+ session: null;
91
+ messageId?: string | null;
92
+ };
93
+ error: AuthError;
94
+ };
95
+ export declare type AuthTokenResponse = {
96
+ data: {
97
+ user: User;
98
+ session: Session;
99
+ };
100
+ error: null;
101
+ } | {
102
+ data: {
103
+ user: null;
104
+ session: null;
105
+ };
106
+ error: AuthError;
107
+ };
108
+ export declare type AuthTokenResponsePassword = {
109
+ data: {
110
+ user: User;
111
+ session: Session;
112
+ weakPassword?: WeakPassword;
113
+ };
114
+ error: null;
115
+ } | {
116
+ data: {
117
+ user: null;
118
+ session: null;
119
+ weakPassword?: null;
120
+ };
121
+ error: AuthError;
122
+ };
123
+ export declare type OAuthResponse = {
124
+ data: {
125
+ provider: Provider;
126
+ url: string;
127
+ };
128
+ error: null;
129
+ } | {
130
+ data: {
131
+ provider: Provider;
132
+ url: null;
133
+ };
134
+ error: AuthError;
135
+ };
136
+ export declare type SSOResponse = {
137
+ data: {
138
+ /**
139
+ * URL to open in a browser which will complete the sign-in flow by
140
+ * taking the user to the identity provider's authentication flow.
141
+ *
142
+ * On browsers you can set the URL to `window.location.href` to take
143
+ * the user to the authentication flow.
144
+ */
145
+ url: string;
146
+ };
147
+ error: null;
148
+ } | {
149
+ data: null;
150
+ error: AuthError;
151
+ };
152
+ export declare type UserResponse = {
153
+ data: {
154
+ user: User;
155
+ };
156
+ error: null;
157
+ } | {
158
+ data: {
159
+ user: null;
160
+ };
161
+ error: AuthError;
162
+ };
163
+ export interface Session {
164
+ /**
165
+ * The oauth provider token. If present, this can be used to make external API requests to the oauth provider used.
166
+ */
167
+ provider_token?: string | null;
168
+ /**
169
+ * The oauth provider refresh token. If present, this can be used to refresh the provider_token via the oauth provider's API.
170
+ * Not all oauth providers return a provider refresh token. If the provider_refresh_token is missing, please refer to the oauth provider's documentation for information on how to obtain the provider refresh token.
171
+ */
172
+ provider_refresh_token?: string | null;
173
+ /**
174
+ * The access token jwt. It is recommended to set the JWT_EXPIRY to a shorter expiry value.
175
+ */
176
+ access_token: string;
177
+ /**
178
+ * A one-time used refresh token that never expires.
179
+ */
180
+ refresh_token: string;
181
+ /**
182
+ * The number of seconds until the token expires (since it was issued). Returned when a login is confirmed.
183
+ */
184
+ expires_in: number;
185
+ /**
186
+ * A timestamp of when the token will expire. Returned when a login is confirmed.
187
+ */
188
+ expires_at?: number;
189
+ token_type: string;
190
+ user: User;
191
+ }
192
+ /**
193
+ * An authentication methord reference (AMR) entry.
194
+ *
195
+ * An entry designates what method was used by the user to verify their
196
+ * identity and at what time.
197
+ *
198
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}.
199
+ */
200
+ export interface AMREntry {
201
+ /** Authentication method name. */
202
+ method: 'password' | 'otp' | 'oauth' | 'mfa/totp' | string;
203
+ /**
204
+ * Timestamp when the method was successfully used. Represents number of
205
+ * seconds since 1st January 1970 (UNIX epoch) in UTC.
206
+ */
207
+ timestamp: number;
208
+ }
209
+ export interface UserIdentity {
210
+ id: string;
211
+ user_id: string;
212
+ identity_data?: {
213
+ [key: string]: any;
214
+ };
215
+ identity_id: string;
216
+ provider: string;
217
+ created_at?: string;
218
+ last_sign_in_at?: string;
219
+ updated_at?: string;
220
+ }
221
+ /**
222
+ * A MFA factor.
223
+ *
224
+ * @see {@link GoTrueMFAApi#enroll}
225
+ * @see {@link GoTrueMFAApi#listFactors}
226
+ * @see {@link GoTrueMFAAdminApi#listFactors}
227
+ */
228
+ export interface Factor {
229
+ /** ID of the factor. */
230
+ id: string;
231
+ /** Friendly name of the factor, useful to disambiguate between multiple factors. */
232
+ friendly_name?: string;
233
+ /**
234
+ * Type of factor. Only `totp` supported with this version but may change in
235
+ * future versions.
236
+ */
237
+ factor_type: 'totp' | string;
238
+ /** Factor's status. */
239
+ status: 'verified' | 'unverified';
240
+ created_at: string;
241
+ updated_at: string;
242
+ }
243
+ export interface UserAppMetadata {
244
+ provider?: string;
245
+ [key: string]: any;
246
+ }
247
+ export interface UserMetadata {
248
+ [key: string]: any;
249
+ }
250
+ export interface User {
251
+ id: string;
252
+ app_metadata: UserAppMetadata;
253
+ user_metadata: UserMetadata;
254
+ aud: string;
255
+ confirmation_sent_at?: string;
256
+ recovery_sent_at?: string;
257
+ email_change_sent_at?: string;
258
+ new_email?: string;
259
+ new_phone?: string;
260
+ invited_at?: string;
261
+ action_link?: string;
262
+ email?: string;
263
+ phone?: string;
264
+ created_at: string;
265
+ confirmed_at?: string;
266
+ email_confirmed_at?: string;
267
+ phone_confirmed_at?: string;
268
+ last_sign_in_at?: string;
269
+ role?: string;
270
+ updated_at?: string;
271
+ identities?: UserIdentity[];
272
+ factors?: Factor[];
273
+ }
274
+ export interface UserAttributes {
275
+ /**
276
+ * The user's email.
277
+ */
278
+ email?: string;
279
+ /**
280
+ * The user's phone.
281
+ */
282
+ phone?: string;
283
+ /**
284
+ * The user's password.
285
+ */
286
+ password?: string;
287
+ /**
288
+ * The nonce sent for reauthentication if the user's password is to be updated.
289
+ *
290
+ * Call reauthenticate() to obtain the nonce first.
291
+ */
292
+ nonce?: string;
293
+ /**
294
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
295
+ *
296
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
297
+ *
298
+ */
299
+ data?: object;
300
+ }
301
+ export interface AdminUserAttributes extends Omit<UserAttributes, 'data'> {
302
+ /**
303
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
304
+ *
305
+ *
306
+ * The `user_metadata` should be a JSON object that includes user-specific info, such as their first and last name.
307
+ *
308
+ * Note: When using the GoTrueAdminApi and wanting to modify a user's metadata,
309
+ * this attribute is used instead of UserAttributes data.
310
+ *
311
+ */
312
+ user_metadata?: object;
313
+ /**
314
+ * A custom data object to store the user's application specific metadata. This maps to the `auth.users.app_metadata` column.
315
+ *
316
+ * Only a service role can modify.
317
+ *
318
+ * The `app_metadata` should be a JSON object that includes app-specific info, such as identity providers, roles, and other
319
+ * access control information.
320
+ */
321
+ app_metadata?: object;
322
+ /**
323
+ * Confirms the user's email address if set to true.
324
+ *
325
+ * Only a service role can modify.
326
+ */
327
+ email_confirm?: boolean;
328
+ /**
329
+ * Confirms the user's phone number if set to true.
330
+ *
331
+ * Only a service role can modify.
332
+ */
333
+ phone_confirm?: boolean;
334
+ /**
335
+ * Determines how long a user is banned for.
336
+ *
337
+ * The format for the ban duration follows a strict sequence of decimal numbers with a unit suffix.
338
+ * Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
339
+ *
340
+ * For example, some possible durations include: '300ms', '2h45m'.
341
+ *
342
+ * Setting the ban duration to 'none' lifts the ban on the user.
343
+ */
344
+ ban_duration?: string | 'none';
345
+ /**
346
+ * The `role` claim set in the user's access token JWT.
347
+ *
348
+ * When a user signs up, this role is set to `authenticated` by default. You should only modify the `role` if you need to provision several levels of admin access that have different permissions on individual columns in your database.
349
+ *
350
+ * Setting this role to `service_role` is not recommended as it grants the user admin privileges.
351
+ */
352
+ role?: string;
353
+ }
354
+ export interface Subscription {
355
+ /**
356
+ * The subscriber UUID. This will be set by the client.
357
+ */
358
+ id: string;
359
+ /**
360
+ * The function to call every time there is an event. eg: (eventName) => {}
361
+ */
362
+ callback: (event: AuthChangeEvent, session: Session | null) => void;
363
+ /**
364
+ * Call this to remove the listener.
365
+ */
366
+ unsubscribe: () => void;
367
+ }
368
+ export interface UpdatableFactorAttributes {
369
+ friendlyName: string;
370
+ }
371
+ export declare type SignUpWithPasswordCredentials = {
372
+ /** The user's email address. */
373
+ email: string;
374
+ /** The user's password. */
375
+ password: string;
376
+ options?: {
377
+ /** The redirect url embedded in the email link */
378
+ emailRedirectTo?: string;
379
+ /**
380
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
381
+ *
382
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
383
+ */
384
+ data?: object;
385
+ /** Verification token received when the user completes the captcha on the site. */
386
+ captchaToken?: string;
387
+ };
388
+ } | {
389
+ /** The user's phone number. */
390
+ phone: string;
391
+ /** The user's password. */
392
+ password: string;
393
+ options?: {
394
+ /**
395
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
396
+ *
397
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
398
+ */
399
+ data?: object;
400
+ /** Verification token received when the user completes the captcha on the site. Requires a configured WhatsApp sender on Twilio */
401
+ captchaToken?: string;
402
+ /** Messaging channel to use (e.g. whatsapp or sms) */
403
+ channel?: 'sms' | 'whatsapp';
404
+ };
405
+ };
406
+ export declare type SignInWithPasswordCredentials = {
407
+ /** The user's email address. */
408
+ email: string;
409
+ /** The user's password. */
410
+ password: string;
411
+ options?: {
412
+ /** Verification token received when the user completes the captcha on the site. */
413
+ captchaToken?: string;
414
+ };
415
+ } | {
416
+ /** The user's phone number. */
417
+ phone: string;
418
+ /** The user's password. */
419
+ password: string;
420
+ options?: {
421
+ /**
422
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
423
+ *
424
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
425
+ */
426
+ data?: object;
427
+ /** Verification token received when the user completes the captcha on the site. */
428
+ captchaToken?: string;
429
+ };
430
+ };
431
+ export declare type SignInWithPasswordlessCredentials = {
432
+ /** The user's email address. */
433
+ email: string;
434
+ options?: {
435
+ /** The redirect url embedded in the email link */
436
+ emailRedirectTo?: string;
437
+ /** If set to false, this method will not create a new user. Defaults to true. */
438
+ shouldCreateUser?: boolean;
439
+ /**
440
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
441
+ *
442
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
443
+ */
444
+ data?: object;
445
+ /** Verification token received when the user completes the captcha on the site. */
446
+ captchaToken?: string;
447
+ };
448
+ } | {
449
+ /** The user's phone number. */
450
+ phone: string;
451
+ options?: {
452
+ /** If set to false, this method will not create a new user. Defaults to true. */
453
+ shouldCreateUser?: boolean;
454
+ /**
455
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
456
+ *
457
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
458
+ */
459
+ data?: object;
460
+ /** Verification token received when the user completes the captcha on the site. */
461
+ captchaToken?: string;
462
+ /** Messaging channel to use (e.g. whatsapp or sms) */
463
+ channel?: 'sms' | 'whatsapp';
464
+ };
465
+ };
466
+ export declare type AuthFlowType = 'implicit' | 'pkce';
467
+ export declare type SignInWithOAuthCredentials = {
468
+ /** One of the providers supported by GoTrue. */
469
+ provider: Provider;
470
+ options?: {
471
+ /** A URL to send the user to after they are confirmed. */
472
+ redirectTo?: string;
473
+ /** A space-separated list of scopes granted to the OAuth application. */
474
+ scopes?: string;
475
+ /** An object of query params */
476
+ queryParams?: {
477
+ [key: string]: string;
478
+ };
479
+ /** If set to true does not immediately redirect the current browser context to visit the OAuth authorization page for the provider. */
480
+ skipBrowserRedirect?: boolean;
481
+ };
482
+ };
483
+ export declare type SignInWithIdTokenCredentials = {
484
+ /** Provider name or OIDC `iss` value identifying which provider should be used to verify the provided token. Supported names: `google`, `apple`, `azure`, `facebook`, `keycloak` (deprecated). */
485
+ provider: 'google' | 'apple' | 'azure' | 'facebook' | string;
486
+ /** OIDC ID token issued by the specified provider. The `iss` claim in the ID token must match the supplied provider. Some ID tokens contain an `at_hash` which require that you provide an `access_token` value to be accepted properly. If the token contains a `nonce` claim you must supply the nonce used to obtain the ID token. */
487
+ token: string;
488
+ /** If the ID token contains an `at_hash` claim, then the hash of this value is compared to the value in the ID token. */
489
+ access_token?: string;
490
+ /** If the ID token contains a `nonce` claim, then the hash of this value is compared to the value in the ID token. */
491
+ nonce?: string;
492
+ options?: {
493
+ /** Verification token received when the user completes the captcha on the site. */
494
+ captchaToken?: string;
495
+ };
496
+ };
497
+ export declare type VerifyOtpParams = VerifyMobileOtpParams | VerifyEmailOtpParams | VerifyTokenHashParams;
498
+ export interface VerifyMobileOtpParams {
499
+ /** The user's phone number. */
500
+ phone: string;
501
+ /** The otp sent to the user's phone number. */
502
+ token: string;
503
+ /** The user's verification type. */
504
+ type: MobileOtpType;
505
+ options?: {
506
+ /** A URL to send the user to after they are confirmed. */
507
+ redirectTo?: string;
508
+ /**
509
+ * Verification token received when the user completes the captcha on the site.
510
+ *
511
+ * @deprecated
512
+ */
513
+ captchaToken?: string;
514
+ };
515
+ }
516
+ export interface VerifyEmailOtpParams {
517
+ /** The user's email address. */
518
+ email: string;
519
+ /** The otp sent to the user's email address. */
520
+ token: string;
521
+ /** The user's verification type. */
522
+ type: EmailOtpType;
523
+ options?: {
524
+ /** A URL to send the user to after they are confirmed. */
525
+ redirectTo?: string;
526
+ /** Verification token received when the user completes the captcha on the site.
527
+ *
528
+ * @deprecated
529
+ */
530
+ captchaToken?: string;
531
+ };
532
+ }
533
+ export interface VerifyTokenHashParams {
534
+ /** The token hash used in an email link */
535
+ token_hash: string;
536
+ /** The user's verification type. */
537
+ type: EmailOtpType;
538
+ }
539
+ export declare type MobileOtpType = 'sms' | 'phone_change';
540
+ export declare type EmailOtpType = 'signup' | 'invite' | 'magiclink' | 'recovery' | 'email_change' | 'email';
541
+ export declare type ResendParams = {
542
+ type: Extract<EmailOtpType, 'signup' | 'email_change'>;
543
+ email: string;
544
+ options?: {
545
+ /** A URL to send the user to after they have signed-in. */
546
+ emailRedirectTo?: string;
547
+ /** Verification token received when the user completes the captcha on the site. */
548
+ captchaToken?: string;
549
+ };
550
+ } | {
551
+ type: Extract<MobileOtpType, 'sms' | 'phone_change'>;
552
+ phone: string;
553
+ options?: {
554
+ /** Verification token received when the user completes the captcha on the site. */
555
+ captchaToken?: string;
556
+ };
557
+ };
558
+ export declare type SignInWithSSO = {
559
+ /** UUID of the SSO provider to invoke single-sign on to. */
560
+ providerId: string;
561
+ options?: {
562
+ /** A URL to send the user to after they have signed-in. */
563
+ redirectTo?: string;
564
+ /** Verification token received when the user completes the captcha on the site. */
565
+ captchaToken?: string;
566
+ };
567
+ } | {
568
+ /** Domain name of the organization for which to invoke single-sign on. */
569
+ domain: string;
570
+ options?: {
571
+ /** A URL to send the user to after they have signed-in. */
572
+ redirectTo?: string;
573
+ /** Verification token received when the user completes the captcha on the site. */
574
+ captchaToken?: string;
575
+ };
576
+ };
577
+ export declare type GenerateSignupLinkParams = {
578
+ type: 'signup';
579
+ email: string;
580
+ password: string;
581
+ options?: Pick<GenerateLinkOptions, 'data' | 'redirectTo'>;
582
+ };
583
+ export declare type GenerateInviteOrMagiclinkParams = {
584
+ type: 'invite' | 'magiclink';
585
+ /** The user's email */
586
+ email: string;
587
+ options?: Pick<GenerateLinkOptions, 'data' | 'redirectTo'>;
588
+ };
589
+ export declare type GenerateRecoveryLinkParams = {
590
+ type: 'recovery';
591
+ /** The user's email */
592
+ email: string;
593
+ options?: Pick<GenerateLinkOptions, 'redirectTo'>;
594
+ };
595
+ export declare type GenerateEmailChangeLinkParams = {
596
+ type: 'email_change_current' | 'email_change_new';
597
+ /** The user's email */
598
+ email: string;
599
+ /**
600
+ * The user's new email. Only required if type is 'email_change_current' or 'email_change_new'.
601
+ */
602
+ newEmail: string;
603
+ options?: Pick<GenerateLinkOptions, 'redirectTo'>;
604
+ };
605
+ export interface GenerateLinkOptions {
606
+ /**
607
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
608
+ *
609
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
610
+ */
611
+ data?: object;
612
+ /** The URL which will be appended to the email link generated. */
613
+ redirectTo?: string;
614
+ }
615
+ export declare type GenerateLinkParams = GenerateSignupLinkParams | GenerateInviteOrMagiclinkParams | GenerateRecoveryLinkParams | GenerateEmailChangeLinkParams;
616
+ export declare type GenerateLinkResponse = {
617
+ data: {
618
+ properties: GenerateLinkProperties;
619
+ user: User;
620
+ };
621
+ error: null;
622
+ } | {
623
+ data: {
624
+ properties: null;
625
+ user: null;
626
+ };
627
+ error: AuthError;
628
+ };
629
+ /** The properties related to the email link generated */
630
+ export declare type GenerateLinkProperties = {
631
+ /**
632
+ * The email link to send to the user.
633
+ * The action_link follows the following format: auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
634
+ * */
635
+ action_link: string;
636
+ /**
637
+ * The raw email OTP.
638
+ * You should send this in the email if you want your users to verify using an OTP instead of the action link.
639
+ * */
640
+ email_otp: string;
641
+ /**
642
+ * The hashed token appended to the action link.
643
+ * */
644
+ hashed_token: string;
645
+ /** The URL appended to the action link. */
646
+ redirect_to: string;
647
+ /** The verification type that the email link is associated to. */
648
+ verification_type: GenerateLinkType;
649
+ };
650
+ export declare type GenerateLinkType = 'signup' | 'invite' | 'magiclink' | 'recovery' | 'email_change_current' | 'email_change_new';
651
+ export declare type MFAEnrollParams = {
652
+ /** The type of factor being enrolled. */
653
+ factorType: 'totp';
654
+ /** Domain which the user is enrolled with. */
655
+ issuer?: string;
656
+ /** Human readable name assigned to the factor. */
657
+ friendlyName?: string;
658
+ };
659
+ export declare type MFAUnenrollParams = {
660
+ /** ID of the factor being unenrolled. */
661
+ factorId: string;
662
+ };
663
+ export declare type MFAVerifyParams = {
664
+ /** ID of the factor being verified. Returned in enroll(). */
665
+ factorId: string;
666
+ /** ID of the challenge being verified. Returned in challenge(). */
667
+ challengeId: string;
668
+ /** Verification code provided by the user. */
669
+ code: string;
670
+ };
671
+ export declare type MFAChallengeParams = {
672
+ /** ID of the factor to be challenged. Returned in enroll(). */
673
+ factorId: string;
674
+ };
675
+ export declare type MFAChallengeAndVerifyParams = {
676
+ /** ID of the factor being verified. Returned in enroll(). */
677
+ factorId: string;
678
+ /** Verification code provided by the user. */
679
+ code: string;
680
+ };
681
+ export declare type AuthMFAVerifyResponse = {
682
+ data: {
683
+ /** New access token (JWT) after successful verification. */
684
+ access_token: string;
685
+ /** Type of token, typically `Bearer`. */
686
+ token_type: string;
687
+ /** Number of seconds in which the access token will expire. */
688
+ expires_in: number;
689
+ /** Refresh token you can use to obtain new access tokens when expired. */
690
+ refresh_token: string;
691
+ /** Updated user profile. */
692
+ user: User;
693
+ };
694
+ error: null;
695
+ } | {
696
+ data: null;
697
+ error: AuthError;
698
+ };
699
+ export declare type AuthMFAEnrollResponse = {
700
+ data: {
701
+ /** ID of the factor that was just enrolled (in an unverified state). */
702
+ id: string;
703
+ /** Type of MFA factor. Only `totp` supported for now. */
704
+ type: 'totp';
705
+ /** TOTP enrollment information. */
706
+ totp: {
707
+ /** Contains a QR code encoding the authenticator URI. You can
708
+ * convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
709
+ * the value. Avoid logging this value to the console. */
710
+ qr_code: string;
711
+ /** The TOTP secret (also encoded in the QR code). Show this secret
712
+ * in a password-style field to the user, in case they are unable to
713
+ * scan the QR code. Avoid logging this value to the console. */
714
+ secret: string;
715
+ /** The authenticator URI encoded within the QR code, should you need
716
+ * to use it. Avoid loggin this value to the console. */
717
+ uri: string;
718
+ };
719
+ };
720
+ error: null;
721
+ } | {
722
+ data: null;
723
+ error: AuthError;
724
+ };
725
+ export declare type AuthMFAUnenrollResponse = {
726
+ data: {
727
+ /** ID of the factor that was successfully unenrolled. */
728
+ id: string;
729
+ };
730
+ error: null;
731
+ } | {
732
+ data: null;
733
+ error: AuthError;
734
+ };
735
+ export declare type AuthMFAChallengeResponse = {
736
+ data: {
737
+ /** ID of the newly created challenge. */
738
+ id: string;
739
+ /** Timestamp in UNIX seconds when this challenge will no longer be usable. */
740
+ expires_at: number;
741
+ };
742
+ error: null;
743
+ } | {
744
+ data: null;
745
+ error: AuthError;
746
+ };
747
+ export declare type AuthMFAListFactorsResponse = {
748
+ data: {
749
+ /** All available factors (verified and unverified). */
750
+ all: Factor[];
751
+ /** Only verified TOTP factors. (A subset of `all`.) */
752
+ totp: Factor[];
753
+ };
754
+ error: null;
755
+ } | {
756
+ data: null;
757
+ error: AuthError;
758
+ };
759
+ export declare type AuthenticatorAssuranceLevels = 'aal1' | 'aal2';
760
+ export declare type AuthMFAGetAuthenticatorAssuranceLevelResponse = {
761
+ data: {
762
+ /** Current AAL level of the session. */
763
+ currentLevel: AuthenticatorAssuranceLevels | null;
764
+ /**
765
+ * Next possible AAL level for the session. If the next level is higher
766
+ * than the current one, the user should go through MFA.
767
+ *
768
+ * @see {@link GoTrueMFAApi#challenge}
769
+ */
770
+ nextLevel: AuthenticatorAssuranceLevels | null;
771
+ /**
772
+ * A list of all authentication methods attached to this session. Use
773
+ * the information here to detect the last time a user verified a
774
+ * factor, for example if implementing a step-up scenario.
775
+ */
776
+ currentAuthenticationMethods: AMREntry[];
777
+ };
778
+ error: null;
779
+ } | {
780
+ data: null;
781
+ error: AuthError;
782
+ };
783
+ /**
784
+ * Contains the full multi-factor authentication API.
785
+ *
786
+ */
787
+ export interface GoTrueMFAApi {
788
+ /**
789
+ * Starts the enrollment process for a new Multi-Factor Authentication (MFA)
790
+ * factor. This method creates a new `unverified` factor.
791
+ * To verify a factor, present the QR code or secret to the user and ask them to add it to their
792
+ * authenticator app.
793
+ * The user has to enter the code from their authenticator app to verify it.
794
+ *
795
+ * Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to `aal2`.
796
+ *
797
+ */
798
+ enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse>;
799
+ /**
800
+ * Prepares a challenge used to verify that a user has access to a MFA
801
+ * factor.
802
+ */
803
+ challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse>;
804
+ /**
805
+ * Verifies a code against a challenge. The verification code is
806
+ * provided by the user by entering a code seen in their authenticator app.
807
+ */
808
+ verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>;
809
+ /**
810
+ * Unenroll removes a MFA factor.
811
+ * A user has to have an `aal2` authenticator level in order to unenroll a `verified` factor.
812
+ */
813
+ unenroll(params: MFAUnenrollParams): Promise<AuthMFAUnenrollResponse>;
814
+ /**
815
+ * Helper method which creates a challenge and immediately uses the given code to verify against it thereafter. The verification code is
816
+ * provided by the user by entering a code seen in their authenticator app.
817
+ */
818
+ challengeAndVerify(params: MFAChallengeAndVerifyParams): Promise<AuthMFAVerifyResponse>;
819
+ /**
820
+ * Returns the list of MFA factors enabled for this user.
821
+ *
822
+ * @see {@link GoTrueMFAApi#enroll}
823
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}
824
+ * @see {@link GoTrueClient#getUser}
825
+ *
826
+ */
827
+ listFactors(): Promise<AuthMFAListFactorsResponse>;
828
+ /**
829
+ * Returns the Authenticator Assurance Level (AAL) for the active session.
830
+ *
831
+ * - `aal1` (or `null`) means that the user's identity has been verified only
832
+ * with a conventional login (email+password, OTP, magic link, social login,
833
+ * etc.).
834
+ * - `aal2` means that the user's identity has been verified both with a conventional login and at least one MFA factor.
835
+ *
836
+ * Although this method returns a promise, it's fairly quick (microseconds)
837
+ * and rarely uses the network. You can use this to check whether the current
838
+ * user needs to be shown a screen to verify their MFA factors.
839
+ *
840
+ */
841
+ getAuthenticatorAssuranceLevel(): Promise<AuthMFAGetAuthenticatorAssuranceLevelResponse>;
842
+ }
843
+ /**
844
+ * @expermental
845
+ */
846
+ export declare type AuthMFAAdminDeleteFactorResponse = {
847
+ data: {
848
+ /** ID of the factor that was successfully deleted. */
849
+ id: string;
850
+ };
851
+ error: null;
852
+ } | {
853
+ data: null;
854
+ error: AuthError;
855
+ };
856
+ /**
857
+ * @expermental
858
+ */
859
+ export declare type AuthMFAAdminDeleteFactorParams = {
860
+ /** ID of the MFA factor to delete. */
861
+ id: string;
862
+ /** ID of the user whose factor is being deleted. */
863
+ userId: string;
864
+ };
865
+ /**
866
+ * @expermental
867
+ */
868
+ export declare type AuthMFAAdminListFactorsResponse = {
869
+ data: {
870
+ /** All factors attached to the user. */
871
+ factors: Factor[];
872
+ };
873
+ error: null;
874
+ } | {
875
+ data: null;
876
+ error: AuthError;
877
+ };
878
+ /**
879
+ * @expermental
880
+ */
881
+ export declare type AuthMFAAdminListFactorsParams = {
882
+ /** ID of the user. */
883
+ userId: string;
884
+ };
885
+ /**
886
+ * Contains the full multi-factor authentication administration API.
887
+ *
888
+ * @expermental
889
+ */
890
+ export interface GoTrueAdminMFAApi {
891
+ /**
892
+ * Lists all factors associated to a user.
893
+ *
894
+ */
895
+ listFactors(params: AuthMFAAdminListFactorsParams): Promise<AuthMFAAdminListFactorsResponse>;
896
+ /**
897
+ * Deletes a factor on a user. This will log the user out of all active
898
+ * sessions if the deleted factor was verified.
899
+ *
900
+ * @see {@link GoTrueMFAApi#unenroll}
901
+ *
902
+ * @expermental
903
+ */
904
+ deleteFactor(params: AuthMFAAdminDeleteFactorParams): Promise<AuthMFAAdminDeleteFactorResponse>;
905
+ }
906
+ declare type AnyFunction = (...args: any[]) => any;
907
+ declare type MaybePromisify<T> = T | Promise<T>;
908
+ declare type PromisifyMethods<T> = {
909
+ [K in keyof T]: T[K] extends AnyFunction ? (...args: Parameters<T[K]>) => MaybePromisify<ReturnType<T[K]>> : T[K];
910
+ };
911
+ export declare type SupportedStorage = PromisifyMethods<Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>>;
912
+ export declare type InitializeResult = {
913
+ error: AuthError | null;
914
+ };
915
+ export declare type CallRefreshTokenResult = {
916
+ session: Session;
917
+ error: null;
918
+ } | {
919
+ session: null;
920
+ error: AuthError;
921
+ };
922
+ export declare type Pagination = {
923
+ [key: string]: any;
924
+ nextPage: number | null;
925
+ lastPage: number;
926
+ total: number;
927
+ };
928
+ export declare type PageParams = {
929
+ /** The page number */
930
+ page?: number;
931
+ /** Number of items returned per page */
932
+ perPage?: number;
933
+ };
934
+ export declare type SignOut = {
935
+ /**
936
+ * Determines which sessions should be
937
+ * logged out. Global means all
938
+ * sessions by this account. Local
939
+ * means only this session. Others
940
+ * means all other sessions except the
941
+ * current one. When using others,
942
+ * there is no sign-out event fired on
943
+ * the current session!
944
+ */
945
+ scope?: 'global' | 'local' | 'others';
946
+ };
947
+ export {};
948
+ //# sourceMappingURL=types.d.ts.map