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