@supabase/auth-js 2.58.1-canary.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 (192) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -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 +278 -0
  14. package/dist/main/GoTrueAdminApi.js.map +1 -0
  15. package/dist/main/GoTrueClient.d.ts +531 -0
  16. package/dist/main/GoTrueClient.d.ts.map +1 -0
  17. package/dist/main/GoTrueClient.js +2564 -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 +36 -0
  22. package/dist/main/index.js.map +1 -0
  23. package/dist/main/lib/base64url.d.ts +76 -0
  24. package/dist/main/lib/base64url.d.ts.map +1 -0
  25. package/dist/main/lib/base64url.js +269 -0
  26. package/dist/main/lib/base64url.js.map +1 -0
  27. package/dist/main/lib/constants.d.ts +26 -0
  28. package/dist/main/lib/constants.d.ts.map +1 -0
  29. package/dist/main/lib/constants.js +31 -0
  30. package/dist/main/lib/constants.js.map +1 -0
  31. package/dist/main/lib/error-codes.d.ts +7 -0
  32. package/dist/main/lib/error-codes.d.ts.map +1 -0
  33. package/dist/main/lib/error-codes.js +3 -0
  34. package/dist/main/lib/error-codes.js.map +1 -0
  35. package/dist/main/lib/errors.d.ts +100 -0
  36. package/dist/main/lib/errors.d.ts.map +1 -0
  37. package/dist/main/lib/errors.js +137 -0
  38. package/dist/main/lib/errors.js.map +1 -0
  39. package/dist/main/lib/fetch.d.ts +34 -0
  40. package/dist/main/lib/fetch.d.ts.map +1 -0
  41. package/dist/main/lib/fetch.js +194 -0
  42. package/dist/main/lib/fetch.js.map +1 -0
  43. package/dist/main/lib/helpers.d.ts +67 -0
  44. package/dist/main/lib/helpers.d.ts.map +1 -0
  45. package/dist/main/lib/helpers.js +388 -0
  46. package/dist/main/lib/helpers.js.map +1 -0
  47. package/dist/main/lib/local-storage.d.ts +9 -0
  48. package/dist/main/lib/local-storage.d.ts.map +1 -0
  49. package/dist/main/lib/local-storage.js +21 -0
  50. package/dist/main/lib/local-storage.js.map +1 -0
  51. package/dist/main/lib/locks.d.ts +64 -0
  52. package/dist/main/lib/locks.d.ts.map +1 -0
  53. package/dist/main/lib/locks.js +187 -0
  54. package/dist/main/lib/locks.js.map +1 -0
  55. package/dist/main/lib/polyfills.d.ts +5 -0
  56. package/dist/main/lib/polyfills.d.ts.map +1 -0
  57. package/dist/main/lib/polyfills.js +29 -0
  58. package/dist/main/lib/polyfills.js.map +1 -0
  59. package/dist/main/lib/types.d.ts +1130 -0
  60. package/dist/main/lib/types.d.ts.map +1 -0
  61. package/dist/main/lib/types.js +22 -0
  62. package/dist/main/lib/types.js.map +1 -0
  63. package/dist/main/lib/version.d.ts +2 -0
  64. package/dist/main/lib/version.d.ts.map +1 -0
  65. package/dist/main/lib/version.js +11 -0
  66. package/dist/main/lib/version.js.map +1 -0
  67. package/dist/main/lib/web3/ethereum.d.ts +96 -0
  68. package/dist/main/lib/web3/ethereum.d.ts.map +1 -0
  69. package/dist/main/lib/web3/ethereum.js +66 -0
  70. package/dist/main/lib/web3/ethereum.js.map +1 -0
  71. package/dist/main/lib/web3/solana.d.ts +160 -0
  72. package/dist/main/lib/web3/solana.d.ts.map +1 -0
  73. package/dist/main/lib/web3/solana.js +4 -0
  74. package/dist/main/lib/web3/solana.js.map +1 -0
  75. package/dist/main/lib/webauthn.d.ts +274 -0
  76. package/dist/main/lib/webauthn.d.ts.map +1 -0
  77. package/dist/main/lib/webauthn.dom.d.ts +583 -0
  78. package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
  79. package/dist/main/lib/webauthn.dom.js +4 -0
  80. package/dist/main/lib/webauthn.dom.js.map +1 -0
  81. package/dist/main/lib/webauthn.errors.d.ts +80 -0
  82. package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
  83. package/dist/main/lib/webauthn.errors.js +265 -0
  84. package/dist/main/lib/webauthn.errors.js.map +1 -0
  85. package/dist/main/lib/webauthn.js +702 -0
  86. package/dist/main/lib/webauthn.js.map +1 -0
  87. package/dist/module/AuthAdminApi.d.ts +4 -0
  88. package/dist/module/AuthAdminApi.d.ts.map +1 -0
  89. package/dist/module/AuthAdminApi.js +4 -0
  90. package/dist/module/AuthAdminApi.js.map +1 -0
  91. package/dist/module/AuthClient.d.ts +4 -0
  92. package/dist/module/AuthClient.d.ts.map +1 -0
  93. package/dist/module/AuthClient.js +4 -0
  94. package/dist/module/AuthClient.js.map +1 -0
  95. package/dist/module/GoTrueAdminApi.d.ts +99 -0
  96. package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
  97. package/dist/module/GoTrueAdminApi.js +275 -0
  98. package/dist/module/GoTrueAdminApi.js.map +1 -0
  99. package/dist/module/GoTrueClient.d.ts +531 -0
  100. package/dist/module/GoTrueClient.d.ts.map +1 -0
  101. package/dist/module/GoTrueClient.js +2559 -0
  102. package/dist/module/GoTrueClient.js.map +1 -0
  103. package/dist/module/index.d.ts +9 -0
  104. package/dist/module/index.d.ts.map +1 -0
  105. package/dist/module/index.js +9 -0
  106. package/dist/module/index.js.map +1 -0
  107. package/dist/module/lib/base64url.d.ts +76 -0
  108. package/dist/module/lib/base64url.d.ts.map +1 -0
  109. package/dist/module/lib/base64url.js +257 -0
  110. package/dist/module/lib/base64url.js.map +1 -0
  111. package/dist/module/lib/constants.d.ts +26 -0
  112. package/dist/module/lib/constants.d.ts.map +1 -0
  113. package/dist/module/lib/constants.js +28 -0
  114. package/dist/module/lib/constants.js.map +1 -0
  115. package/dist/module/lib/error-codes.d.ts +7 -0
  116. package/dist/module/lib/error-codes.d.ts.map +1 -0
  117. package/dist/module/lib/error-codes.js +2 -0
  118. package/dist/module/lib/error-codes.js.map +1 -0
  119. package/dist/module/lib/errors.d.ts +100 -0
  120. package/dist/module/lib/errors.d.ts.map +1 -0
  121. package/dist/module/lib/errors.js +116 -0
  122. package/dist/module/lib/errors.js.map +1 -0
  123. package/dist/module/lib/fetch.d.ts +34 -0
  124. package/dist/module/lib/fetch.d.ts.map +1 -0
  125. package/dist/module/lib/fetch.js +184 -0
  126. package/dist/module/lib/fetch.js.map +1 -0
  127. package/dist/module/lib/helpers.d.ts +67 -0
  128. package/dist/module/lib/helpers.d.ts.map +1 -0
  129. package/dist/module/lib/helpers.js +329 -0
  130. package/dist/module/lib/helpers.js.map +1 -0
  131. package/dist/module/lib/local-storage.d.ts +9 -0
  132. package/dist/module/lib/local-storage.d.ts.map +1 -0
  133. package/dist/module/lib/local-storage.js +18 -0
  134. package/dist/module/lib/local-storage.js.map +1 -0
  135. package/dist/module/lib/locks.d.ts +64 -0
  136. package/dist/module/lib/locks.d.ts.map +1 -0
  137. package/dist/module/lib/locks.js +179 -0
  138. package/dist/module/lib/locks.js.map +1 -0
  139. package/dist/module/lib/polyfills.d.ts +5 -0
  140. package/dist/module/lib/polyfills.d.ts.map +1 -0
  141. package/dist/module/lib/polyfills.js +26 -0
  142. package/dist/module/lib/polyfills.js.map +1 -0
  143. package/dist/module/lib/types.d.ts +1130 -0
  144. package/dist/module/lib/types.d.ts.map +1 -0
  145. package/dist/module/lib/types.js +19 -0
  146. package/dist/module/lib/types.js.map +1 -0
  147. package/dist/module/lib/version.d.ts +2 -0
  148. package/dist/module/lib/version.d.ts.map +1 -0
  149. package/dist/module/lib/version.js +8 -0
  150. package/dist/module/lib/version.js.map +1 -0
  151. package/dist/module/lib/web3/ethereum.d.ts +96 -0
  152. package/dist/module/lib/web3/ethereum.d.ts.map +1 -0
  153. package/dist/module/lib/web3/ethereum.js +60 -0
  154. package/dist/module/lib/web3/ethereum.js.map +1 -0
  155. package/dist/module/lib/web3/solana.d.ts +160 -0
  156. package/dist/module/lib/web3/solana.d.ts.map +1 -0
  157. package/dist/module/lib/web3/solana.js +3 -0
  158. package/dist/module/lib/web3/solana.js.map +1 -0
  159. package/dist/module/lib/webauthn.d.ts +274 -0
  160. package/dist/module/lib/webauthn.d.ts.map +1 -0
  161. package/dist/module/lib/webauthn.dom.d.ts +583 -0
  162. package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
  163. package/dist/module/lib/webauthn.dom.js +3 -0
  164. package/dist/module/lib/webauthn.dom.js.map +1 -0
  165. package/dist/module/lib/webauthn.errors.d.ts +80 -0
  166. package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
  167. package/dist/module/lib/webauthn.errors.js +257 -0
  168. package/dist/module/lib/webauthn.errors.js.map +1 -0
  169. package/dist/module/lib/webauthn.js +685 -0
  170. package/dist/module/lib/webauthn.js.map +1 -0
  171. package/package.json +49 -0
  172. package/src/AuthAdminApi.ts +5 -0
  173. package/src/AuthClient.ts +5 -0
  174. package/src/GoTrueAdminApi.ts +352 -0
  175. package/src/GoTrueClient.ts +3483 -0
  176. package/src/index.ts +13 -0
  177. package/src/lib/base64url.ts +308 -0
  178. package/src/lib/constants.ts +34 -0
  179. package/src/lib/error-codes.ts +90 -0
  180. package/src/lib/errors.ts +165 -0
  181. package/src/lib/fetch.ts +283 -0
  182. package/src/lib/helpers.ts +416 -0
  183. package/src/lib/local-storage.ts +21 -0
  184. package/src/lib/locks.ts +225 -0
  185. package/src/lib/polyfills.ts +23 -0
  186. package/src/lib/types.ts +1450 -0
  187. package/src/lib/version.ts +7 -0
  188. package/src/lib/web3/ethereum.ts +184 -0
  189. package/src/lib/web3/solana.ts +186 -0
  190. package/src/lib/webauthn.dom.ts +636 -0
  191. package/src/lib/webauthn.errors.ts +317 -0
  192. package/src/lib/webauthn.ts +929 -0
@@ -0,0 +1,1450 @@
1
+ import { AuthError } from './errors'
2
+ import { Fetch } from './fetch'
3
+ import { EIP1193Provider, EthereumSignInInput, Hex } from './web3/ethereum'
4
+ import type { SolanaSignInInput, SolanaSignInOutput } from './web3/solana'
5
+ import {
6
+ ServerCredentialCreationOptions,
7
+ ServerCredentialRequestOptions,
8
+ WebAuthnApi,
9
+ } from './webauthn'
10
+ import {
11
+ AuthenticationCredential,
12
+ PublicKeyCredentialCreationOptionsFuture,
13
+ PublicKeyCredentialRequestOptionsFuture,
14
+ RegistrationCredential,
15
+ } from './webauthn.dom'
16
+
17
+ /** One of the providers supported by GoTrue. */
18
+ export type Provider =
19
+ | 'apple'
20
+ | 'azure'
21
+ | 'bitbucket'
22
+ | 'discord'
23
+ | 'facebook'
24
+ | 'figma'
25
+ | 'github'
26
+ | 'gitlab'
27
+ | 'google'
28
+ | 'kakao'
29
+ | 'keycloak'
30
+ | 'linkedin'
31
+ | 'linkedin_oidc'
32
+ | 'notion'
33
+ | 'slack'
34
+ | 'slack_oidc'
35
+ | 'spotify'
36
+ | 'twitch'
37
+ | 'twitter'
38
+ | 'workos'
39
+ | 'zoom'
40
+ | 'fly'
41
+
42
+ export type AuthChangeEventMFA = 'MFA_CHALLENGE_VERIFIED'
43
+
44
+ export type AuthChangeEvent =
45
+ | 'INITIAL_SESSION'
46
+ | 'PASSWORD_RECOVERY'
47
+ | 'SIGNED_IN'
48
+ | 'SIGNED_OUT'
49
+ | 'TOKEN_REFRESHED'
50
+ | 'USER_UPDATED'
51
+ | AuthChangeEventMFA
52
+
53
+ /**
54
+ * Provide your own global lock implementation instead of the default
55
+ * implementation. The function should acquire a lock for the duration of the
56
+ * `fn` async function, such that no other client instances will be able to
57
+ * hold it at the same time.
58
+ *
59
+ * @experimental
60
+ *
61
+ * @param name Name of the lock to be acquired.
62
+ * @param acquireTimeout If negative, no timeout should occur. If positive it
63
+ * should throw an Error with an `isAcquireTimeout`
64
+ * property set to true if the operation fails to be
65
+ * acquired after this much time (ms).
66
+ * @param fn The operation to execute when the lock is acquired.
67
+ */
68
+ export type LockFunc = <R>(name: string, acquireTimeout: number, fn: () => Promise<R>) => Promise<R>
69
+
70
+ export type GoTrueClientOptions = {
71
+ /* The URL of the GoTrue server. */
72
+ url?: string
73
+ /* Any additional headers to send to the GoTrue server. */
74
+ headers?: { [key: string]: string }
75
+ /* Optional key name used for storing tokens in local storage. */
76
+ storageKey?: string
77
+ /* Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user. */
78
+ detectSessionInUrl?: boolean
79
+ /* Set to "true" if you want to automatically refresh the token before expiring. */
80
+ autoRefreshToken?: boolean
81
+ /* 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. */
82
+ persistSession?: boolean
83
+ /* Provide your own local storage implementation to use instead of the browser's local storage. */
84
+ storage?: SupportedStorage
85
+ /**
86
+ * Stores the user object in a separate storage location from the rest of the session data. When non-null, `storage` will only store a JSON object containing the access and refresh token and some adjacent metadata, while `userStorage` will only contain the user object under the key `storageKey + '-user'`.
87
+ *
88
+ * When this option is set and cookie storage is used, `getSession()` and other functions that load a session from the cookie store might not return back a user. It's very important to always use `getUser()` to fetch a user object in those scenarios.
89
+ *
90
+ * @experimental
91
+ */
92
+ userStorage?: SupportedStorage
93
+ /* A custom fetch implementation. */
94
+ fetch?: Fetch
95
+ /* If set to 'pkce' PKCE flow. Defaults to the 'implicit' flow otherwise */
96
+ flowType?: AuthFlowType
97
+ /* 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. */
98
+ debug?: boolean | ((message: string, ...args: any[]) => void)
99
+ /**
100
+ * Provide your own locking mechanism based on the environment. By default no locking is done at this time.
101
+ *
102
+ * @experimental
103
+ */
104
+ lock?: LockFunc
105
+ /**
106
+ * Set to "true" if there is a custom authorization header set globally.
107
+ * @experimental
108
+ */
109
+ hasCustomAuthorizationHeader?: boolean
110
+ }
111
+
112
+ const WeakPasswordReasons = ['length', 'characters', 'pwned'] as const
113
+
114
+ export type WeakPasswordReasons = (typeof WeakPasswordReasons)[number]
115
+ export type WeakPassword = {
116
+ reasons: WeakPasswordReasons[]
117
+ message: string
118
+ }
119
+
120
+ /**
121
+ * Resolve mapped types and show the derived keys and their types when hovering in
122
+ * VS Code, instead of just showing the names those mapped types are defined with.
123
+ */
124
+ export type Prettify<T> = T extends Function ? T : { [K in keyof T]: T[K] }
125
+
126
+ /**
127
+ * A stricter version of TypeScript's Omit that only allows omitting keys that actually exist.
128
+ * This prevents typos and ensures type safety at compile time.
129
+ * Unlike regular Omit, this will error if you try to omit a non-existent key.
130
+ */
131
+ export type StrictOmit<T, K extends keyof T> = Omit<T, K>
132
+
133
+ /**
134
+ * a shared result type that encapsulates errors instead of throwing them, allows you to optionally specify the ErrorType
135
+ */
136
+ export type RequestResult<T, ErrorType extends Error = AuthError> =
137
+ | {
138
+ data: T
139
+ error: null
140
+ }
141
+ | {
142
+ data: null
143
+ error: Error extends AuthError ? AuthError : ErrorType
144
+ }
145
+
146
+ /**
147
+ * similar to RequestResult except it allows you to destructure the possible shape of the success response
148
+ * {@see RequestResult}
149
+ */
150
+ export type RequestResultSafeDestructure<T> =
151
+ | { data: T; error: null }
152
+ | {
153
+ data: T extends object ? { [K in keyof T]: null } : null
154
+ error: AuthError
155
+ }
156
+
157
+ export type AuthResponse = RequestResultSafeDestructure<{
158
+ user: User | null
159
+ session: Session | null
160
+ }>
161
+
162
+ export type AuthResponsePassword = RequestResultSafeDestructure<{
163
+ user: User | null
164
+ session: Session | null
165
+ weak_password?: WeakPassword | null
166
+ }>
167
+
168
+ /**
169
+ * AuthOtpResponse is returned when OTP is used.
170
+ *
171
+ * {@see AuthResponse}
172
+ */
173
+ export type AuthOtpResponse = RequestResultSafeDestructure<{
174
+ user: null
175
+ session: null
176
+ messageId?: string | null
177
+ }>
178
+
179
+ export type AuthTokenResponse = RequestResultSafeDestructure<{
180
+ user: User
181
+ session: Session
182
+ }>
183
+
184
+ export type AuthTokenResponsePassword = RequestResultSafeDestructure<{
185
+ user: User
186
+ session: Session
187
+ weakPassword?: WeakPassword
188
+ }>
189
+
190
+ export type OAuthResponse =
191
+ | {
192
+ data: {
193
+ provider: Provider
194
+ url: string
195
+ }
196
+ error: null
197
+ }
198
+ | {
199
+ data: {
200
+ provider: Provider
201
+ url: null
202
+ }
203
+ error: AuthError
204
+ }
205
+
206
+ export type SSOResponse = RequestResult<{
207
+ /**
208
+ * URL to open in a browser which will complete the sign-in flow by
209
+ * taking the user to the identity provider's authentication flow.
210
+ *
211
+ * On browsers you can set the URL to `window.location.href` to take
212
+ * the user to the authentication flow.
213
+ */
214
+ url: string
215
+ }>
216
+
217
+ export type UserResponse = RequestResultSafeDestructure<{
218
+ user: User
219
+ }>
220
+
221
+ export interface Session {
222
+ /**
223
+ * The oauth provider token. If present, this can be used to make external API requests to the oauth provider used.
224
+ */
225
+ provider_token?: string | null
226
+ /**
227
+ * The oauth provider refresh token. If present, this can be used to refresh the provider_token via the oauth provider's API.
228
+ * 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.
229
+ */
230
+ provider_refresh_token?: string | null
231
+ /**
232
+ * The access token jwt. It is recommended to set the JWT_EXPIRY to a shorter expiry value.
233
+ */
234
+ access_token: string
235
+ /**
236
+ * A one-time used refresh token that never expires.
237
+ */
238
+ refresh_token: string
239
+ /**
240
+ * The number of seconds until the token expires (since it was issued). Returned when a login is confirmed.
241
+ */
242
+ expires_in: number
243
+ /**
244
+ * A timestamp of when the token will expire. Returned when a login is confirmed.
245
+ */
246
+ expires_at?: number
247
+ token_type: 'bearer'
248
+
249
+ /**
250
+ * When using a separate user storage, accessing properties of this object will throw an error.
251
+ */
252
+ user: User
253
+ }
254
+
255
+ const AMRMethods = [
256
+ 'password',
257
+ 'otp',
258
+ 'oauth',
259
+ 'totp',
260
+ 'mfa/totp',
261
+ 'mfa/phone',
262
+ 'mfa/webauthn',
263
+ 'anonymous',
264
+ 'sso/saml',
265
+ 'magiclink',
266
+ 'web3',
267
+ ] as const
268
+
269
+ export type AMRMethod = (typeof AMRMethods)[number] | (string & {})
270
+
271
+ /**
272
+ * An authentication methord reference (AMR) entry.
273
+ *
274
+ * An entry designates what method was used by the user to verify their
275
+ * identity and at what time.
276
+ *
277
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}.
278
+ */
279
+ export interface AMREntry {
280
+ /** Authentication method name. */
281
+ method: AMRMethod
282
+
283
+ /**
284
+ * Timestamp when the method was successfully used. Represents number of
285
+ * seconds since 1st January 1970 (UNIX epoch) in UTC.
286
+ */
287
+ timestamp: number
288
+ }
289
+
290
+ export interface UserIdentity {
291
+ id: string
292
+ user_id: string
293
+ identity_data?: {
294
+ [key: string]: any
295
+ }
296
+ identity_id: string
297
+ provider: string
298
+ created_at?: string
299
+ last_sign_in_at?: string
300
+ updated_at?: string
301
+ }
302
+
303
+ const FactorTypes = ['totp', 'phone', 'webauthn'] as const
304
+
305
+ /**
306
+ * Type of factor. `totp` and `phone` supported with this version
307
+ */
308
+ export type FactorType = (typeof FactorTypes)[number]
309
+
310
+ const FactorVerificationStatuses = ['verified', 'unverified'] as const
311
+
312
+ /**
313
+ * The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
314
+ */
315
+ type FactorVerificationStatus = (typeof FactorVerificationStatuses)[number]
316
+
317
+ /**
318
+ * A MFA factor.
319
+ *
320
+ * @see {@link GoTrueMFAApi#enroll}
321
+ * @see {@link GoTrueMFAApi#listFactors}
322
+ * @see {@link GoTrueMFAAdminApi#listFactors}
323
+ */
324
+ export type Factor<
325
+ Type extends FactorType = FactorType,
326
+ Status extends FactorVerificationStatus = (typeof FactorVerificationStatuses)[number],
327
+ > = {
328
+ /** ID of the factor. */
329
+ id: string
330
+
331
+ /** Friendly name of the factor, useful to disambiguate between multiple factors. */
332
+ friendly_name?: string
333
+
334
+ /**
335
+ * Type of factor. `totp` and `phone` supported with this version
336
+ */
337
+ factor_type: Type
338
+
339
+ /**
340
+ * The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
341
+ */
342
+ status: Status
343
+
344
+ created_at: string
345
+ updated_at: string
346
+ }
347
+
348
+ export interface UserAppMetadata {
349
+ provider?: string
350
+ [key: string]: any
351
+ }
352
+
353
+ export interface UserMetadata {
354
+ [key: string]: any
355
+ }
356
+
357
+ export interface User {
358
+ id: string
359
+ app_metadata: UserAppMetadata
360
+ user_metadata: UserMetadata
361
+ aud: string
362
+ confirmation_sent_at?: string
363
+ recovery_sent_at?: string
364
+ email_change_sent_at?: string
365
+ new_email?: string
366
+ new_phone?: string
367
+ invited_at?: string
368
+ action_link?: string
369
+ email?: string
370
+ phone?: string
371
+ created_at: string
372
+ confirmed_at?: string
373
+ email_confirmed_at?: string
374
+ phone_confirmed_at?: string
375
+ last_sign_in_at?: string
376
+ role?: string
377
+ updated_at?: string
378
+ identities?: UserIdentity[]
379
+ is_anonymous?: boolean
380
+ is_sso_user?: boolean
381
+ factors?: (Factor<FactorType, 'verified'> | Factor<FactorType, 'unverified'>)[]
382
+ deleted_at?: string
383
+ }
384
+
385
+ export interface UserAttributes {
386
+ /**
387
+ * The user's email.
388
+ */
389
+ email?: string
390
+
391
+ /**
392
+ * The user's phone.
393
+ */
394
+ phone?: string
395
+
396
+ /**
397
+ * The user's password.
398
+ */
399
+ password?: string
400
+
401
+ /**
402
+ * The nonce sent for reauthentication if the user's password is to be updated.
403
+ *
404
+ * Call reauthenticate() to obtain the nonce first.
405
+ */
406
+ nonce?: string
407
+
408
+ /**
409
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
410
+ *
411
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
412
+ *
413
+ */
414
+ data?: object
415
+ }
416
+
417
+ export interface AdminUserAttributes extends Omit<UserAttributes, 'data'> {
418
+ /**
419
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
420
+ *
421
+ *
422
+ * The `user_metadata` should be a JSON object that includes user-specific info, such as their first and last name.
423
+ *
424
+ * Note: When using the GoTrueAdminApi and wanting to modify a user's metadata,
425
+ * this attribute is used instead of UserAttributes data.
426
+ *
427
+ */
428
+ user_metadata?: object
429
+
430
+ /**
431
+ * A custom data object to store the user's application specific metadata. This maps to the `auth.users.app_metadata` column.
432
+ *
433
+ * Only a service role can modify.
434
+ *
435
+ * The `app_metadata` should be a JSON object that includes app-specific info, such as identity providers, roles, and other
436
+ * access control information.
437
+ */
438
+ app_metadata?: object
439
+
440
+ /**
441
+ * Confirms the user's email address if set to true.
442
+ *
443
+ * Only a service role can modify.
444
+ */
445
+ email_confirm?: boolean
446
+
447
+ /**
448
+ * Confirms the user's phone number if set to true.
449
+ *
450
+ * Only a service role can modify.
451
+ */
452
+ phone_confirm?: boolean
453
+
454
+ /**
455
+ * Determines how long a user is banned for.
456
+ *
457
+ * The format for the ban duration follows a strict sequence of decimal numbers with a unit suffix.
458
+ * Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
459
+ *
460
+ * For example, some possible durations include: '300ms', '2h45m'.
461
+ *
462
+ * Setting the ban duration to 'none' lifts the ban on the user.
463
+ */
464
+ ban_duration?: string | 'none'
465
+
466
+ /**
467
+ * The `role` claim set in the user's access token JWT.
468
+ *
469
+ * 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.
470
+ *
471
+ * Setting this role to `service_role` is not recommended as it grants the user admin privileges.
472
+ */
473
+ role?: string
474
+
475
+ /**
476
+ * The `password_hash` for the user's password.
477
+ *
478
+ * Allows you to specify a password hash for the user. This is useful for migrating a user's password hash from another service.
479
+ *
480
+ * Supports bcrypt, scrypt (firebase), and argon2 password hashes.
481
+ */
482
+ password_hash?: string
483
+
484
+ /**
485
+ * The `id` for the user.
486
+ *
487
+ * Allows you to overwrite the default `id` set for the user.
488
+ */
489
+ id?: string
490
+ }
491
+
492
+ export interface Subscription {
493
+ /**
494
+ * The subscriber UUID. This will be set by the client.
495
+ */
496
+ id: string
497
+ /**
498
+ * The function to call every time there is an event. eg: (eventName) => {}
499
+ */
500
+ callback: (event: AuthChangeEvent, session: Session | null) => void
501
+ /**
502
+ * Call this to remove the listener.
503
+ */
504
+ unsubscribe: () => void
505
+ }
506
+
507
+ export type SignInAnonymouslyCredentials = {
508
+ options?: {
509
+ /**
510
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` 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 SignUpWithPasswordCredentials = Prettify<
521
+ PasswordCredentialsBase & {
522
+ options?: {
523
+ emailRedirectTo?: string // only for email
524
+ data?: object
525
+ captchaToken?: string
526
+ channel?: 'sms' | 'whatsapp' // only for phone
527
+ }
528
+ }
529
+ >
530
+
531
+ type PasswordCredentialsBase =
532
+ | { email: string; password: string }
533
+ | { phone: string; password: string }
534
+
535
+ export type SignInWithPasswordCredentials = PasswordCredentialsBase & {
536
+ options?: {
537
+ captchaToken?: string
538
+ }
539
+ }
540
+
541
+ export type SignInWithPasswordlessCredentials =
542
+ | {
543
+ /** The user's email address. */
544
+ email: string
545
+ options?: {
546
+ /** The redirect url embedded in the email link */
547
+ emailRedirectTo?: string
548
+ /** If set to false, this method will not create a new user. Defaults to true. */
549
+ shouldCreateUser?: boolean
550
+ /**
551
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
552
+ *
553
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
554
+ */
555
+ data?: object
556
+ /** Verification token received when the user completes the captcha on the site. */
557
+ captchaToken?: string
558
+ }
559
+ }
560
+ | {
561
+ /** The user's phone number. */
562
+ phone: string
563
+ options?: {
564
+ /** If set to false, this method will not create a new user. Defaults to true. */
565
+ shouldCreateUser?: boolean
566
+ /**
567
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
568
+ *
569
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
570
+ */
571
+ data?: object
572
+ /** Verification token received when the user completes the captcha on the site. */
573
+ captchaToken?: string
574
+ /** Messaging channel to use (e.g. whatsapp or sms) */
575
+ channel?: 'sms' | 'whatsapp'
576
+ }
577
+ }
578
+
579
+ export type AuthFlowType = 'implicit' | 'pkce'
580
+ export type SignInWithOAuthCredentials = {
581
+ /** One of the providers supported by GoTrue. */
582
+ provider: Provider
583
+ options?: {
584
+ /** A URL to send the user to after they are confirmed. */
585
+ redirectTo?: string
586
+ /** A space-separated list of scopes granted to the OAuth application. */
587
+ scopes?: string
588
+ /** An object of query params */
589
+ queryParams?: { [key: string]: string }
590
+ /** If set to true does not immediately redirect the current browser context to visit the OAuth authorization page for the provider. */
591
+ skipBrowserRedirect?: boolean
592
+ }
593
+ }
594
+
595
+ export type SignInWithIdTokenCredentials = {
596
+ /** Provider name or OIDC `iss` value identifying which provider should be used to verify the provided token. Supported names: `google`, `apple`, `azure`, `facebook`, `kakao`, `keycloak` (deprecated). */
597
+ provider: 'google' | 'apple' | 'azure' | 'facebook' | 'kakao' | (string & {})
598
+ /** 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. */
599
+ token: string
600
+ /** If the ID token contains an `at_hash` claim, then the hash of this value is compared to the value in the ID token. */
601
+ access_token?: string
602
+ /** If the ID token contains a `nonce` claim, then the hash of this value is compared to the value in the ID token. */
603
+ nonce?: string
604
+ options?: {
605
+ /** Verification token received when the user completes the captcha on the site. */
606
+ captchaToken?: string
607
+ }
608
+ }
609
+
610
+ export type SolanaWallet = {
611
+ signIn?: (...inputs: SolanaSignInInput[]) => Promise<SolanaSignInOutput | SolanaSignInOutput[]>
612
+ publicKey?: {
613
+ toBase58: () => string
614
+ } | null
615
+
616
+ signMessage?: (message: Uint8Array, encoding?: 'utf8' | string) => Promise<Uint8Array> | undefined
617
+ }
618
+
619
+ export type SolanaWeb3Credentials =
620
+ | {
621
+ chain: 'solana'
622
+
623
+ /** Wallet interface to use. If not specified will default to `window.solana`. */
624
+ wallet?: SolanaWallet
625
+
626
+ /** Optional statement to include in the Sign in with Solana message. Must not include new line characters. Most wallets like Phantom **require specifying a statement!** */
627
+ statement?: string
628
+
629
+ options?: {
630
+ /** URL to use with the wallet interface. Some wallets do not allow signing a message for URLs different from the current page. */
631
+ url?: string
632
+
633
+ /** Verification token received when the user completes the captcha on the site. */
634
+ captchaToken?: string
635
+
636
+ signInWithSolana?: Partial<
637
+ Omit<SolanaSignInInput, 'version' | 'chain' | 'domain' | 'uri' | 'statement'>
638
+ >
639
+ }
640
+ }
641
+ | {
642
+ chain: 'solana'
643
+
644
+ /** Sign in with Solana compatible message. Must include `Issued At`, `URI` and `Version`. */
645
+ message: string
646
+
647
+ /** Ed25519 signature of the message. */
648
+ signature: Uint8Array
649
+
650
+ options?: {
651
+ /** Verification token received when the user completes the captcha on the site. */
652
+ captchaToken?: string
653
+ }
654
+ }
655
+
656
+ export type EthereumWallet = EIP1193Provider
657
+
658
+ export type EthereumWeb3Credentials =
659
+ | {
660
+ chain: 'ethereum'
661
+
662
+ /** Wallet interface to use. If not specified will default to `window.ethereum`. */
663
+ wallet?: EthereumWallet
664
+
665
+ /** Optional statement to include in the Sign in with Ethereum message. Must not include new line characters. Most wallets like Phantom **require specifying a statement!** */
666
+ statement?: string
667
+
668
+ options?: {
669
+ /** URL to use with the wallet interface. Some wallets do not allow signing a message for URLs different from the current page. */
670
+ url?: string
671
+
672
+ /** Verification token received when the user completes the captcha on the site. */
673
+ captchaToken?: string
674
+
675
+ signInWithEthereum?: Partial<
676
+ Omit<EthereumSignInInput, 'version' | 'domain' | 'uri' | 'statement'>
677
+ >
678
+ }
679
+ }
680
+ | {
681
+ chain: 'ethereum'
682
+
683
+ /** Sign in with Ethereum compatible message. Must include `Issued At`, `URI` and `Version`. */
684
+ message: string
685
+
686
+ /** Ethereum curve (secp256k1) signature of the message. */
687
+ signature: Hex
688
+
689
+ options?: {
690
+ /** Verification token received when the user completes the captcha on the site. */
691
+ captchaToken?: string
692
+ }
693
+ }
694
+
695
+ export type Web3Credentials = SolanaWeb3Credentials | EthereumWeb3Credentials
696
+
697
+ export type VerifyOtpParams = VerifyMobileOtpParams | VerifyEmailOtpParams | VerifyTokenHashParams
698
+ export interface VerifyMobileOtpParams {
699
+ /** The user's phone number. */
700
+ phone: string
701
+ /** The otp sent to the user's phone number. */
702
+ token: string
703
+ /** The user's verification type. */
704
+ type: MobileOtpType
705
+ options?: {
706
+ /** A URL to send the user to after they are confirmed. */
707
+ redirectTo?: string
708
+
709
+ /**
710
+ * Verification token received when the user completes the captcha on the site.
711
+ *
712
+ * @deprecated
713
+ */
714
+ captchaToken?: string
715
+ }
716
+ }
717
+ export interface VerifyEmailOtpParams {
718
+ /** The user's email address. */
719
+ email: string
720
+ /** The otp sent to the user's email address. */
721
+ token: string
722
+ /** The user's verification type. */
723
+ type: EmailOtpType
724
+ options?: {
725
+ /** A URL to send the user to after they are confirmed. */
726
+ redirectTo?: string
727
+
728
+ /** Verification token received when the user completes the captcha on the site.
729
+ *
730
+ * @deprecated
731
+ */
732
+ captchaToken?: string
733
+ }
734
+ }
735
+
736
+ export interface VerifyTokenHashParams {
737
+ /** The token hash used in an email link */
738
+ token_hash: string
739
+
740
+ /** The user's verification type. */
741
+ type: EmailOtpType
742
+ }
743
+
744
+ export type MobileOtpType = 'sms' | 'phone_change'
745
+ export type EmailOtpType = 'signup' | 'invite' | 'magiclink' | 'recovery' | 'email_change' | 'email'
746
+
747
+ export type ResendParams =
748
+ | {
749
+ type: Extract<EmailOtpType, 'signup' | 'email_change'>
750
+ email: string
751
+ options?: {
752
+ /** A URL to send the user to after they have signed-in. */
753
+ emailRedirectTo?: string
754
+ /** Verification token received when the user completes the captcha on the site. */
755
+ captchaToken?: string
756
+ }
757
+ }
758
+ | {
759
+ type: Extract<MobileOtpType, 'sms' | 'phone_change'>
760
+ phone: string
761
+ options?: {
762
+ /** Verification token received when the user completes the captcha on the site. */
763
+ captchaToken?: string
764
+ }
765
+ }
766
+
767
+ export type SignInWithSSO =
768
+ | {
769
+ /** UUID of the SSO provider to invoke single-sign on to. */
770
+ providerId: string
771
+
772
+ options?: {
773
+ /** A URL to send the user to after they have signed-in. */
774
+ redirectTo?: string
775
+ /** Verification token received when the user completes the captcha on the site. */
776
+ captchaToken?: string
777
+ }
778
+ }
779
+ | {
780
+ /** Domain name of the organization for which to invoke single-sign on. */
781
+ domain: string
782
+
783
+ options?: {
784
+ /** A URL to send the user to after they have signed-in. */
785
+ redirectTo?: string
786
+ /** Verification token received when the user completes the captcha on the site. */
787
+ captchaToken?: string
788
+ }
789
+ }
790
+
791
+ export type GenerateSignupLinkParams = {
792
+ type: 'signup'
793
+ email: string
794
+ password: string
795
+ options?: Pick<GenerateLinkOptions, 'data' | 'redirectTo'>
796
+ }
797
+
798
+ export type GenerateInviteOrMagiclinkParams = {
799
+ type: 'invite' | 'magiclink'
800
+ /** The user's email */
801
+ email: string
802
+ options?: Pick<GenerateLinkOptions, 'data' | 'redirectTo'>
803
+ }
804
+
805
+ export type GenerateRecoveryLinkParams = {
806
+ type: 'recovery'
807
+ /** The user's email */
808
+ email: string
809
+ options?: Pick<GenerateLinkOptions, 'redirectTo'>
810
+ }
811
+
812
+ export type GenerateEmailChangeLinkParams = {
813
+ type: 'email_change_current' | 'email_change_new'
814
+ /** The user's email */
815
+ email: string
816
+ /**
817
+ * The user's new email. Only required if type is 'email_change_current' or 'email_change_new'.
818
+ */
819
+ newEmail: string
820
+ options?: Pick<GenerateLinkOptions, 'redirectTo'>
821
+ }
822
+
823
+ export interface GenerateLinkOptions {
824
+ /**
825
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
826
+ *
827
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
828
+ */
829
+ data?: object
830
+ /** The URL which will be appended to the email link generated. */
831
+ redirectTo?: string
832
+ }
833
+
834
+ export type GenerateLinkParams =
835
+ | GenerateSignupLinkParams
836
+ | GenerateInviteOrMagiclinkParams
837
+ | GenerateRecoveryLinkParams
838
+ | GenerateEmailChangeLinkParams
839
+
840
+ export type GenerateLinkResponse = RequestResultSafeDestructure<{
841
+ properties: GenerateLinkProperties
842
+ user: User
843
+ }>
844
+
845
+ /** The properties related to the email link generated */
846
+ export type GenerateLinkProperties = {
847
+ /**
848
+ * The email link to send to the user.
849
+ * The action_link follows the following format: auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
850
+ * */
851
+ action_link: string
852
+ /**
853
+ * The raw email OTP.
854
+ * You should send this in the email if you want your users to verify using an OTP instead of the action link.
855
+ * */
856
+ email_otp: string
857
+ /**
858
+ * The hashed token appended to the action link.
859
+ * */
860
+ hashed_token: string
861
+ /** The URL appended to the action link. */
862
+ redirect_to: string
863
+ /** The verification type that the email link is associated to. */
864
+ verification_type: GenerateLinkType
865
+ }
866
+
867
+ export type GenerateLinkType =
868
+ | 'signup'
869
+ | 'invite'
870
+ | 'magiclink'
871
+ | 'recovery'
872
+ | 'email_change_current'
873
+ | 'email_change_new'
874
+
875
+ export type MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams | MFAEnrollWebauthnParams
876
+
877
+ export type MFAUnenrollParams = {
878
+ /** ID of the factor being unenrolled. */
879
+ factorId: string
880
+ }
881
+
882
+ type MFAVerifyParamsBase = {
883
+ /** ID of the factor being verified. Returned in enroll(). */
884
+ factorId: string
885
+ /** ID of the challenge being verified. Returned in challenge(). */
886
+ challengeId: string
887
+ }
888
+
889
+ type MFAVerifyTOTPParamFields = {
890
+ /** Verification code provided by the user. */
891
+ code: string
892
+ }
893
+
894
+ export type MFAVerifyTOTPParams = Prettify<MFAVerifyParamsBase & MFAVerifyTOTPParamFields>
895
+
896
+ type MFAVerifyPhoneParamFields = MFAVerifyTOTPParamFields
897
+
898
+ export type MFAVerifyPhoneParams = Prettify<MFAVerifyParamsBase & MFAVerifyPhoneParamFields>
899
+
900
+ type MFAVerifyWebauthnParamFieldsBase = {
901
+ /** Relying party ID */
902
+ rpId: string
903
+ /** Relying party origins */
904
+ rpOrigins?: string[]
905
+ }
906
+
907
+ type MFAVerifyWebauthnCredentialParamFields<T extends 'create' | 'request' = 'create' | 'request'> =
908
+ {
909
+ /** Operation type */
910
+ type: T
911
+ /** Creation response from the authenticator (for enrollment/unverified factors) */
912
+ credential_response: T extends 'create' ? RegistrationCredential : AuthenticationCredential
913
+ }
914
+
915
+ /**
916
+ * WebAuthn-specific fields for MFA verification.
917
+ * Supports both credential creation (registration) and request (authentication) flows.
918
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
919
+ */
920
+ export type MFAVerifyWebauthnParamFields<T extends 'create' | 'request' = 'create' | 'request'> = {
921
+ webauthn: MFAVerifyWebauthnParamFieldsBase & MFAVerifyWebauthnCredentialParamFields<T>
922
+ }
923
+
924
+ /**
925
+ * Parameters for WebAuthn MFA verification.
926
+ * Used to verify WebAuthn credentials after challenge.
927
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
928
+ * @see {@link https://w3c.github.io/webauthn/#sctn-verifying-assertion W3C WebAuthn Spec - Verifying an Authentication Assertion}
929
+ */
930
+ export type MFAVerifyWebauthnParams<T extends 'create' | 'request' = 'create' | 'request'> =
931
+ Prettify<MFAVerifyParamsBase & MFAVerifyWebauthnParamFields<T>>
932
+
933
+ export type MFAVerifyParams = MFAVerifyTOTPParams | MFAVerifyPhoneParams | MFAVerifyWebauthnParams
934
+
935
+ type MFAChallengeParamsBase = {
936
+ /** ID of the factor to be challenged. Returned in enroll(). */
937
+ factorId: string
938
+ }
939
+
940
+ const MFATOTPChannels = ['sms', 'whatsapp'] as const
941
+ export type MFATOTPChannel = (typeof MFATOTPChannels)[number]
942
+
943
+ export type MFAChallengeTOTPParams = Prettify<MFAChallengeParamsBase>
944
+
945
+ type MFAChallengePhoneParamFields<Channel extends MFATOTPChannel = MFATOTPChannel> = {
946
+ /** Messaging channel to use (e.g. whatsapp or sms). Only relevant for phone factors */
947
+ channel: Channel
948
+ }
949
+
950
+ export type MFAChallengePhoneParams = Prettify<
951
+ MFAChallengeParamsBase & MFAChallengePhoneParamFields
952
+ >
953
+
954
+ /** WebAuthn parameters for WebAuthn factor challenge */
955
+ type MFAChallengeWebauthnParamFields = {
956
+ webauthn: {
957
+ /** Relying party ID */
958
+ rpId: string
959
+ /** Relying party origins*/
960
+ rpOrigins?: string[]
961
+ }
962
+ }
963
+
964
+ /**
965
+ * Parameters for initiating a WebAuthn MFA challenge.
966
+ * Includes Relying Party information needed for WebAuthn ceremonies.
967
+ * @see {@link https://w3c.github.io/webauthn/#sctn-rp-operations W3C WebAuthn Spec - Relying Party Operations}
968
+ */
969
+ export type MFAChallengeWebauthnParams = Prettify<
970
+ MFAChallengeParamsBase & MFAChallengeWebauthnParamFields
971
+ >
972
+
973
+ export type MFAChallengeParams =
974
+ | MFAChallengeTOTPParams
975
+ | MFAChallengePhoneParams
976
+ | MFAChallengeWebauthnParams
977
+
978
+ type MFAChallengeAndVerifyParamsBase = Omit<MFAVerifyParamsBase, 'challengeId'>
979
+
980
+ type MFAChallengeAndVerifyTOTPParamFields = MFAVerifyTOTPParamFields
981
+
982
+ type MFAChallengeAndVerifyTOTPParams = Prettify<
983
+ MFAChallengeAndVerifyParamsBase & MFAChallengeAndVerifyTOTPParamFields
984
+ >
985
+
986
+ export type MFAChallengeAndVerifyParams = MFAChallengeAndVerifyTOTPParams
987
+
988
+ /**
989
+ * Data returned after successful MFA verification.
990
+ * Contains new session tokens and updated user information.
991
+ */
992
+ export type AuthMFAVerifyResponseData = {
993
+ /** New access token (JWT) after successful verification. */
994
+ access_token: string
995
+
996
+ /** Type of token, always `bearer`. */
997
+ token_type: 'bearer'
998
+
999
+ /** Number of seconds in which the access token will expire. */
1000
+ expires_in: number
1001
+
1002
+ /** Refresh token you can use to obtain new access tokens when expired. */
1003
+ refresh_token: string
1004
+
1005
+ /** Updated user profile. */
1006
+ user: User
1007
+ }
1008
+
1009
+ /**
1010
+ * Response type for MFA verification operations.
1011
+ * Returns session tokens on successful verification.
1012
+ */
1013
+ export type AuthMFAVerifyResponse = RequestResult<AuthMFAVerifyResponseData>
1014
+
1015
+ export type AuthMFAEnrollResponse =
1016
+ | AuthMFAEnrollTOTPResponse
1017
+ | AuthMFAEnrollPhoneResponse
1018
+ | AuthMFAEnrollWebauthnResponse
1019
+
1020
+ export type AuthMFAUnenrollResponse = RequestResult<{
1021
+ /** ID of the factor that was successfully unenrolled. */
1022
+ id: string
1023
+ }>
1024
+
1025
+ type AuthMFAChallengeResponseBase<T extends FactorType> = {
1026
+ /** ID of the newly created challenge. */
1027
+ id: string
1028
+
1029
+ /** Factor Type which generated the challenge */
1030
+ type: T
1031
+
1032
+ /** Timestamp in UNIX seconds when this challenge will no longer be usable. */
1033
+ expires_at: number
1034
+ }
1035
+
1036
+ type AuthMFAChallengeTOTPResponseFields = {
1037
+ /** no extra fields for now, kept for consistency and for possible future changes */
1038
+ }
1039
+
1040
+ export type AuthMFAChallengeTOTPResponse = RequestResult<
1041
+ Prettify<AuthMFAChallengeResponseBase<'totp'> & AuthMFAChallengeTOTPResponseFields>
1042
+ >
1043
+
1044
+ type AuthMFAChallengePhoneResponseFields = {
1045
+ /** no extra fields for now, kept for consistency and for possible future changes */
1046
+ }
1047
+
1048
+ export type AuthMFAChallengePhoneResponse = RequestResult<
1049
+ Prettify<AuthMFAChallengeResponseBase<'phone'> & AuthMFAChallengePhoneResponseFields>
1050
+ >
1051
+
1052
+ type AuthMFAChallengeWebauthnResponseFields = {
1053
+ webauthn:
1054
+ | {
1055
+ type: 'create'
1056
+ credential_options: { publicKey: PublicKeyCredentialCreationOptionsFuture }
1057
+ }
1058
+ | {
1059
+ type: 'request'
1060
+ credential_options: { publicKey: PublicKeyCredentialRequestOptionsFuture }
1061
+ }
1062
+ }
1063
+
1064
+ /**
1065
+ * Response type for WebAuthn MFA challenge.
1066
+ * Contains credential creation or request options from the server.
1067
+ * @see {@link https://w3c.github.io/webauthn/#sctn-credential-creation W3C WebAuthn Spec - Credential Creation}
1068
+ */
1069
+ export type AuthMFAChallengeWebauthnResponse = RequestResult<
1070
+ Prettify<AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFields>
1071
+ >
1072
+
1073
+ type AuthMFAChallengeWebauthnResponseFieldsJSON = {
1074
+ webauthn:
1075
+ | {
1076
+ type: 'create'
1077
+ credential_options: { publicKey: ServerCredentialCreationOptions }
1078
+ }
1079
+ | {
1080
+ type: 'request'
1081
+ credential_options: { publicKey: ServerCredentialRequestOptions }
1082
+ }
1083
+ }
1084
+
1085
+ /**
1086
+ * JSON-serializable version of WebAuthn challenge response.
1087
+ * Used for server communication with base64url-encoded binary fields.
1088
+ */
1089
+ export type AuthMFAChallengeWebauthnResponseDataJSON = Prettify<
1090
+ AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFieldsJSON
1091
+ >
1092
+
1093
+ /**
1094
+ * Server response type for WebAuthn MFA challenge.
1095
+ * Contains JSON-formatted WebAuthn options ready for browser API.
1096
+ */
1097
+ export type AuthMFAChallengeWebauthnServerResponse =
1098
+ RequestResult<AuthMFAChallengeWebauthnResponseDataJSON>
1099
+
1100
+ export type AuthMFAChallengeResponse =
1101
+ | AuthMFAChallengeTOTPResponse
1102
+ | AuthMFAChallengePhoneResponse
1103
+ | AuthMFAChallengeWebauthnResponse
1104
+
1105
+ /** response of ListFactors, which should contain all the types of factors that are available, this ensures we always include all */
1106
+ export type AuthMFAListFactorsResponse<T extends typeof FactorTypes = typeof FactorTypes> =
1107
+ RequestResult<
1108
+ {
1109
+ /** All available factors (verified and unverified). */
1110
+ all: Prettify<Factor>[]
1111
+
1112
+ // Dynamically create a property for each factor type with only verified factors
1113
+ } & {
1114
+ [K in T[number]]: Prettify<Factor<K, 'verified'>>[]
1115
+ }
1116
+ >
1117
+
1118
+ export type AuthenticatorAssuranceLevels = 'aal1' | 'aal2'
1119
+
1120
+ export type AuthMFAGetAuthenticatorAssuranceLevelResponse = RequestResult<{
1121
+ /** Current AAL level of the session. */
1122
+ currentLevel: AuthenticatorAssuranceLevels | null
1123
+
1124
+ /**
1125
+ * Next possible AAL level for the session. If the next level is higher
1126
+ * than the current one, the user should go through MFA.
1127
+ *
1128
+ * @see {@link GoTrueMFAApi#challenge}
1129
+ */
1130
+ nextLevel: AuthenticatorAssuranceLevels | null
1131
+
1132
+ /**
1133
+ * A list of all authentication methods attached to this session. Use
1134
+ * the information here to detect the last time a user verified a
1135
+ * factor, for example if implementing a step-up scenario.
1136
+ */
1137
+ currentAuthenticationMethods: AMREntry[]
1138
+ }>
1139
+
1140
+ /**
1141
+ * Contains the full multi-factor authentication API.
1142
+ *
1143
+ */
1144
+ export interface GoTrueMFAApi {
1145
+ /**
1146
+ * Starts the enrollment process for a new Multi-Factor Authentication (MFA)
1147
+ * factor. This method creates a new `unverified` factor.
1148
+ * To verify a factor, present the QR code or secret to the user and ask them to add it to their
1149
+ * authenticator app.
1150
+ * The user has to enter the code from their authenticator app to verify it.
1151
+ *
1152
+ * Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to `aal2`.
1153
+ */
1154
+ enroll(params: MFAEnrollTOTPParams): Promise<AuthMFAEnrollTOTPResponse>
1155
+ enroll(params: MFAEnrollPhoneParams): Promise<AuthMFAEnrollPhoneResponse>
1156
+ enroll(params: MFAEnrollWebauthnParams): Promise<AuthMFAEnrollWebauthnResponse>
1157
+ enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse>
1158
+
1159
+ /**
1160
+ * Prepares a challenge used to verify that a user has access to a MFA
1161
+ * factor.
1162
+ */
1163
+ challenge(params: MFAChallengeTOTPParams): Promise<Prettify<AuthMFAChallengeTOTPResponse>>
1164
+ challenge(params: MFAChallengePhoneParams): Promise<Prettify<AuthMFAChallengePhoneResponse>>
1165
+ challenge(params: MFAChallengeWebauthnParams): Promise<Prettify<AuthMFAChallengeWebauthnResponse>>
1166
+ challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse>
1167
+
1168
+ /**
1169
+ * Verifies a code against a challenge. The verification code is
1170
+ * provided by the user by entering a code seen in their authenticator app.
1171
+ */
1172
+ verify(params: MFAVerifyTOTPParams): Promise<AuthMFAVerifyResponse>
1173
+ verify(params: MFAVerifyPhoneParams): Promise<AuthMFAVerifyResponse>
1174
+ verify(params: MFAVerifyWebauthnParams): Promise<AuthMFAVerifyResponse>
1175
+ verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>
1176
+
1177
+ /**
1178
+ * Unenroll removes a MFA factor.
1179
+ * A user has to have an `aal2` authenticator level in order to unenroll a `verified` factor.
1180
+ */
1181
+ unenroll(params: MFAUnenrollParams): Promise<AuthMFAUnenrollResponse>
1182
+
1183
+ /**
1184
+ * Helper method which creates a challenge and immediately uses the given code to verify against it thereafter. The verification code is
1185
+ * provided by the user by entering a code seen in their authenticator app.
1186
+ */
1187
+ challengeAndVerify(params: MFAChallengeAndVerifyParams): Promise<AuthMFAVerifyResponse>
1188
+
1189
+ /**
1190
+ * Returns the list of MFA factors enabled for this user.
1191
+ *
1192
+ * @see {@link GoTrueMFAApi#enroll}
1193
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}
1194
+ * @see {@link GoTrueClient#getUser}
1195
+ *
1196
+ */
1197
+ listFactors(): Promise<AuthMFAListFactorsResponse>
1198
+
1199
+ /**
1200
+ * Returns the Authenticator Assurance Level (AAL) for the active session.
1201
+ *
1202
+ * - `aal1` (or `null`) means that the user's identity has been verified only
1203
+ * with a conventional login (email+password, OTP, magic link, social login,
1204
+ * etc.).
1205
+ * - `aal2` means that the user's identity has been verified both with a conventional login and at least one MFA factor.
1206
+ *
1207
+ * Although this method returns a promise, it's fairly quick (microseconds)
1208
+ * and rarely uses the network. You can use this to check whether the current
1209
+ * user needs to be shown a screen to verify their MFA factors.
1210
+ *
1211
+ */
1212
+ getAuthenticatorAssuranceLevel(): Promise<AuthMFAGetAuthenticatorAssuranceLevelResponse>
1213
+
1214
+ // namespace for the webauthn methods
1215
+ webauthn: WebAuthnApi
1216
+ }
1217
+
1218
+ /**
1219
+ * @expermental
1220
+ */
1221
+ export type AuthMFAAdminDeleteFactorResponse = RequestResult<{
1222
+ /** ID of the factor that was successfully deleted. */
1223
+ id: string
1224
+ }>
1225
+ /**
1226
+ * @expermental
1227
+ */
1228
+ export type AuthMFAAdminDeleteFactorParams = {
1229
+ /** ID of the MFA factor to delete. */
1230
+ id: string
1231
+
1232
+ /** ID of the user whose factor is being deleted. */
1233
+ userId: string
1234
+ }
1235
+
1236
+ /**
1237
+ * @expermental
1238
+ */
1239
+ export type AuthMFAAdminListFactorsResponse = RequestResult<{
1240
+ /** All factors attached to the user. */
1241
+ factors: Factor[]
1242
+ }>
1243
+
1244
+ /**
1245
+ * @expermental
1246
+ */
1247
+ export type AuthMFAAdminListFactorsParams = {
1248
+ /** ID of the user. */
1249
+ userId: string
1250
+ }
1251
+
1252
+ /**
1253
+ * Contains the full multi-factor authentication administration API.
1254
+ *
1255
+ * @expermental
1256
+ */
1257
+ export interface GoTrueAdminMFAApi {
1258
+ /**
1259
+ * Lists all factors associated to a user.
1260
+ *
1261
+ */
1262
+ listFactors(params: AuthMFAAdminListFactorsParams): Promise<AuthMFAAdminListFactorsResponse>
1263
+
1264
+ /**
1265
+ * Deletes a factor on a user. This will log the user out of all active
1266
+ * sessions if the deleted factor was verified.
1267
+ *
1268
+ * @see {@link GoTrueMFAApi#unenroll}
1269
+ *
1270
+ * @expermental
1271
+ */
1272
+ deleteFactor(params: AuthMFAAdminDeleteFactorParams): Promise<AuthMFAAdminDeleteFactorResponse>
1273
+ }
1274
+
1275
+ type AnyFunction = (...args: any[]) => any
1276
+ type MaybePromisify<T> = T | Promise<T>
1277
+
1278
+ type PromisifyMethods<T> = {
1279
+ [K in keyof T]: T[K] extends AnyFunction
1280
+ ? (...args: Parameters<T[K]>) => MaybePromisify<ReturnType<T[K]>>
1281
+ : T[K]
1282
+ }
1283
+
1284
+ export type SupportedStorage = PromisifyMethods<
1285
+ Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>
1286
+ > & {
1287
+ /**
1288
+ * If set to `true` signals to the library that the storage medium is used
1289
+ * on a server and the values may not be authentic, such as reading from
1290
+ * request cookies. Implementations should not set this to true if the client
1291
+ * is used on a server that reads storage information from authenticated
1292
+ * sources, such as a secure database or file.
1293
+ */
1294
+ isServer?: boolean
1295
+ }
1296
+
1297
+ export type InitializeResult = { error: AuthError | null }
1298
+
1299
+ export type CallRefreshTokenResult = RequestResult<Session>
1300
+
1301
+ export type Pagination = {
1302
+ [key: string]: any
1303
+ nextPage: number | null
1304
+ lastPage: number
1305
+ total: number
1306
+ }
1307
+
1308
+ export type PageParams = {
1309
+ /** The page number */
1310
+ page?: number
1311
+ /** Number of items returned per page */
1312
+ perPage?: number
1313
+ }
1314
+
1315
+ export type SignOut = {
1316
+ /**
1317
+ * Determines which sessions should be
1318
+ * logged out. Global means all
1319
+ * sessions by this account. Local
1320
+ * means only this session. Others
1321
+ * means all other sessions except the
1322
+ * current one. When using others,
1323
+ * there is no sign-out event fired on
1324
+ * the current session!
1325
+ */
1326
+ scope?: 'global' | 'local' | 'others'
1327
+ }
1328
+
1329
+ type MFAEnrollParamsBase<T extends FactorType> = {
1330
+ /** The type of factor being enrolled. */
1331
+ factorType: T
1332
+ /** Human readable name assigned to the factor. */
1333
+ friendlyName?: string
1334
+ }
1335
+
1336
+ type MFAEnrollTOTPParamFields = {
1337
+ /** Domain which the user is enrolled with. */
1338
+ issuer?: string
1339
+ }
1340
+
1341
+ export type MFAEnrollTOTPParams = Prettify<MFAEnrollParamsBase<'totp'> & MFAEnrollTOTPParamFields>
1342
+
1343
+ type MFAEnrollPhoneParamFields = {
1344
+ /** Phone number associated with a factor. Number should conform to E.164 format */
1345
+ phone: string
1346
+ }
1347
+ export type MFAEnrollPhoneParams = Prettify<
1348
+ MFAEnrollParamsBase<'phone'> & MFAEnrollPhoneParamFields
1349
+ >
1350
+
1351
+ type MFAEnrollWebauthnFields = {
1352
+ /** no extra fields for now, kept for consistency and for possible future changes */
1353
+ }
1354
+
1355
+ /**
1356
+ * Parameters for enrolling a WebAuthn factor.
1357
+ * Creates an unverified WebAuthn factor that must be verified with a credential.
1358
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1359
+ */
1360
+ export type MFAEnrollWebauthnParams = Prettify<
1361
+ MFAEnrollParamsBase<'webauthn'> & MFAEnrollWebauthnFields
1362
+ >
1363
+
1364
+ type AuthMFAEnrollResponseBase<T extends FactorType> = {
1365
+ /** ID of the factor that was just enrolled (in an unverified state). */
1366
+ id: string
1367
+
1368
+ /** Type of MFA factor.*/
1369
+ type: T
1370
+
1371
+ /** Friendly name of the factor, useful for distinguishing between factors **/
1372
+ friendly_name?: string
1373
+ }
1374
+
1375
+ type AuthMFAEnrollTOTPResponseFields = {
1376
+ /** TOTP enrollment information. */
1377
+ totp: {
1378
+ /** Contains a QR code encoding the authenticator URI. You can
1379
+ * convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
1380
+ * the value. Avoid logging this value to the console. */
1381
+ qr_code: string
1382
+
1383
+ /** The TOTP secret (also encoded in the QR code). Show this secret
1384
+ * in a password-style field to the user, in case they are unable to
1385
+ * scan the QR code. Avoid logging this value to the console. */
1386
+ secret: string
1387
+
1388
+ /** The authenticator URI encoded within the QR code, should you need
1389
+ * to use it. Avoid loggin this value to the console. */
1390
+ uri: string
1391
+ }
1392
+ }
1393
+
1394
+ export type AuthMFAEnrollTOTPResponse = RequestResult<
1395
+ Prettify<AuthMFAEnrollResponseBase<'totp'> & AuthMFAEnrollTOTPResponseFields>
1396
+ >
1397
+
1398
+ type AuthMFAEnrollPhoneResponseFields = {
1399
+ /** Phone number of the MFA factor in E.164 format. Used to send messages */
1400
+ phone: string
1401
+ }
1402
+
1403
+ export type AuthMFAEnrollPhoneResponse = RequestResult<
1404
+ Prettify<AuthMFAEnrollResponseBase<'phone'> & AuthMFAEnrollPhoneResponseFields>
1405
+ >
1406
+
1407
+ type AuthMFAEnrollWebauthnFields = {
1408
+ /** no extra fields for now, kept for consistency and for possible future changes */
1409
+ }
1410
+
1411
+ /**
1412
+ * Response type for WebAuthn factor enrollment.
1413
+ * Returns the enrolled factor ID and metadata.
1414
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1415
+ */
1416
+ export type AuthMFAEnrollWebauthnResponse = RequestResult<
1417
+ Prettify<AuthMFAEnrollResponseBase<'webauthn'> & AuthMFAEnrollWebauthnFields>
1418
+ >
1419
+
1420
+ export type JwtHeader = {
1421
+ alg: 'RS256' | 'ES256' | 'HS256'
1422
+ kid: string
1423
+ typ: string
1424
+ }
1425
+
1426
+ export type RequiredClaims = {
1427
+ iss: string
1428
+ sub: string
1429
+ aud: string | string[]
1430
+ exp: number
1431
+ iat: number
1432
+ role: string
1433
+ aal: AuthenticatorAssuranceLevels
1434
+ session_id: string
1435
+ }
1436
+
1437
+ export type JwtPayload = RequiredClaims & {
1438
+ [key: string]: any
1439
+ }
1440
+
1441
+ export interface JWK {
1442
+ kty: 'RSA' | 'EC' | 'oct'
1443
+ key_ops: string[]
1444
+ alg?: string
1445
+ kid?: string
1446
+ [key: string]: any
1447
+ }
1448
+
1449
+ export const SIGN_OUT_SCOPES = ['global', 'local', 'others'] as const
1450
+ export type SignOutScope = (typeof SIGN_OUT_SCOPES)[number]