@depup/supabase__auth-js 2.99.2-depup.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 (195) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/changes.json +5 -0
  4. package/dist/main/AuthAdminApi.d.ts +4 -0
  5. package/dist/main/AuthAdminApi.d.ts.map +1 -0
  6. package/dist/main/AuthAdminApi.js +7 -0
  7. package/dist/main/AuthAdminApi.js.map +1 -0
  8. package/dist/main/AuthClient.d.ts +4 -0
  9. package/dist/main/AuthClient.d.ts.map +1 -0
  10. package/dist/main/AuthClient.js +7 -0
  11. package/dist/main/AuthClient.js.map +1 -0
  12. package/dist/main/GoTrueAdminApi.d.ts +227 -0
  13. package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
  14. package/dist/main/GoTrueAdminApi.js +596 -0
  15. package/dist/main/GoTrueAdminApi.js.map +1 -0
  16. package/dist/main/GoTrueClient.d.ts +783 -0
  17. package/dist/main/GoTrueClient.d.ts.map +1 -0
  18. package/dist/main/GoTrueClient.js +3029 -0
  19. package/dist/main/GoTrueClient.js.map +1 -0
  20. package/dist/main/index.d.ts +9 -0
  21. package/dist/main/index.d.ts.map +1 -0
  22. package/dist/main/index.js +20 -0
  23. package/dist/main/index.js.map +1 -0
  24. package/dist/main/lib/base64url.d.ts +76 -0
  25. package/dist/main/lib/base64url.d.ts.map +1 -0
  26. package/dist/main/lib/base64url.js +269 -0
  27. package/dist/main/lib/base64url.js.map +1 -0
  28. package/dist/main/lib/constants.d.ts +26 -0
  29. package/dist/main/lib/constants.d.ts.map +1 -0
  30. package/dist/main/lib/constants.js +31 -0
  31. package/dist/main/lib/constants.js.map +1 -0
  32. package/dist/main/lib/error-codes.d.ts +7 -0
  33. package/dist/main/lib/error-codes.d.ts.map +1 -0
  34. package/dist/main/lib/error-codes.js +3 -0
  35. package/dist/main/lib/error-codes.js.map +1 -0
  36. package/dist/main/lib/errors.d.ts +243 -0
  37. package/dist/main/lib/errors.d.ts.map +1 -0
  38. package/dist/main/lib/errors.js +289 -0
  39. package/dist/main/lib/errors.js.map +1 -0
  40. package/dist/main/lib/fetch.d.ts +34 -0
  41. package/dist/main/lib/fetch.d.ts.map +1 -0
  42. package/dist/main/lib/fetch.js +184 -0
  43. package/dist/main/lib/fetch.js.map +1 -0
  44. package/dist/main/lib/helpers.d.ts +91 -0
  45. package/dist/main/lib/helpers.d.ts.map +1 -0
  46. package/dist/main/lib/helpers.js +395 -0
  47. package/dist/main/lib/helpers.js.map +1 -0
  48. package/dist/main/lib/local-storage.d.ts +9 -0
  49. package/dist/main/lib/local-storage.d.ts.map +1 -0
  50. package/dist/main/lib/local-storage.js +21 -0
  51. package/dist/main/lib/local-storage.js.map +1 -0
  52. package/dist/main/lib/locks.d.ts +107 -0
  53. package/dist/main/lib/locks.d.ts.map +1 -0
  54. package/dist/main/lib/locks.js +314 -0
  55. package/dist/main/lib/locks.js.map +1 -0
  56. package/dist/main/lib/polyfills.d.ts +5 -0
  57. package/dist/main/lib/polyfills.d.ts.map +1 -0
  58. package/dist/main/lib/polyfills.js +29 -0
  59. package/dist/main/lib/polyfills.js.map +1 -0
  60. package/dist/main/lib/types.d.ts +1861 -0
  61. package/dist/main/lib/types.d.ts.map +1 -0
  62. package/dist/main/lib/types.js +23 -0
  63. package/dist/main/lib/types.js.map +1 -0
  64. package/dist/main/lib/version.d.ts +2 -0
  65. package/dist/main/lib/version.d.ts.map +1 -0
  66. package/dist/main/lib/version.js +11 -0
  67. package/dist/main/lib/version.js.map +1 -0
  68. package/dist/main/lib/web3/ethereum.d.ts +96 -0
  69. package/dist/main/lib/web3/ethereum.d.ts.map +1 -0
  70. package/dist/main/lib/web3/ethereum.js +66 -0
  71. package/dist/main/lib/web3/ethereum.js.map +1 -0
  72. package/dist/main/lib/web3/solana.d.ts +160 -0
  73. package/dist/main/lib/web3/solana.d.ts.map +1 -0
  74. package/dist/main/lib/web3/solana.js +4 -0
  75. package/dist/main/lib/web3/solana.js.map +1 -0
  76. package/dist/main/lib/webauthn.d.ts +276 -0
  77. package/dist/main/lib/webauthn.d.ts.map +1 -0
  78. package/dist/main/lib/webauthn.dom.d.ts +583 -0
  79. package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
  80. package/dist/main/lib/webauthn.dom.js +4 -0
  81. package/dist/main/lib/webauthn.dom.js.map +1 -0
  82. package/dist/main/lib/webauthn.errors.d.ts +80 -0
  83. package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
  84. package/dist/main/lib/webauthn.errors.js +265 -0
  85. package/dist/main/lib/webauthn.errors.js.map +1 -0
  86. package/dist/main/lib/webauthn.js +706 -0
  87. package/dist/main/lib/webauthn.js.map +1 -0
  88. package/dist/module/AuthAdminApi.d.ts +4 -0
  89. package/dist/module/AuthAdminApi.d.ts.map +1 -0
  90. package/dist/module/AuthAdminApi.js +4 -0
  91. package/dist/module/AuthAdminApi.js.map +1 -0
  92. package/dist/module/AuthClient.d.ts +4 -0
  93. package/dist/module/AuthClient.d.ts.map +1 -0
  94. package/dist/module/AuthClient.js +4 -0
  95. package/dist/module/AuthClient.js.map +1 -0
  96. package/dist/module/GoTrueAdminApi.d.ts +227 -0
  97. package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
  98. package/dist/module/GoTrueAdminApi.js +593 -0
  99. package/dist/module/GoTrueAdminApi.js.map +1 -0
  100. package/dist/module/GoTrueClient.d.ts +783 -0
  101. package/dist/module/GoTrueClient.d.ts.map +1 -0
  102. package/dist/module/GoTrueClient.js +3026 -0
  103. package/dist/module/GoTrueClient.js.map +1 -0
  104. package/dist/module/index.d.ts +9 -0
  105. package/dist/module/index.d.ts.map +1 -0
  106. package/dist/module/index.js +9 -0
  107. package/dist/module/index.js.map +1 -0
  108. package/dist/module/lib/base64url.d.ts +76 -0
  109. package/dist/module/lib/base64url.d.ts.map +1 -0
  110. package/dist/module/lib/base64url.js +257 -0
  111. package/dist/module/lib/base64url.js.map +1 -0
  112. package/dist/module/lib/constants.d.ts +26 -0
  113. package/dist/module/lib/constants.d.ts.map +1 -0
  114. package/dist/module/lib/constants.js +28 -0
  115. package/dist/module/lib/constants.js.map +1 -0
  116. package/dist/module/lib/error-codes.d.ts +7 -0
  117. package/dist/module/lib/error-codes.d.ts.map +1 -0
  118. package/dist/module/lib/error-codes.js +2 -0
  119. package/dist/module/lib/error-codes.js.map +1 -0
  120. package/dist/module/lib/errors.d.ts +243 -0
  121. package/dist/module/lib/errors.d.ts.map +1 -0
  122. package/dist/module/lib/errors.js +266 -0
  123. package/dist/module/lib/errors.js.map +1 -0
  124. package/dist/module/lib/fetch.d.ts +34 -0
  125. package/dist/module/lib/fetch.d.ts.map +1 -0
  126. package/dist/module/lib/fetch.js +174 -0
  127. package/dist/module/lib/fetch.js.map +1 -0
  128. package/dist/module/lib/helpers.d.ts +91 -0
  129. package/dist/module/lib/helpers.d.ts.map +1 -0
  130. package/dist/module/lib/helpers.js +368 -0
  131. package/dist/module/lib/helpers.js.map +1 -0
  132. package/dist/module/lib/local-storage.d.ts +9 -0
  133. package/dist/module/lib/local-storage.d.ts.map +1 -0
  134. package/dist/module/lib/local-storage.js +18 -0
  135. package/dist/module/lib/local-storage.js.map +1 -0
  136. package/dist/module/lib/locks.d.ts +107 -0
  137. package/dist/module/lib/locks.d.ts.map +1 -0
  138. package/dist/module/lib/locks.js +306 -0
  139. package/dist/module/lib/locks.js.map +1 -0
  140. package/dist/module/lib/polyfills.d.ts +5 -0
  141. package/dist/module/lib/polyfills.d.ts.map +1 -0
  142. package/dist/module/lib/polyfills.js +26 -0
  143. package/dist/module/lib/polyfills.js.map +1 -0
  144. package/dist/module/lib/types.d.ts +1861 -0
  145. package/dist/module/lib/types.d.ts.map +1 -0
  146. package/dist/module/lib/types.js +20 -0
  147. package/dist/module/lib/types.js.map +1 -0
  148. package/dist/module/lib/version.d.ts +2 -0
  149. package/dist/module/lib/version.d.ts.map +1 -0
  150. package/dist/module/lib/version.js +8 -0
  151. package/dist/module/lib/version.js.map +1 -0
  152. package/dist/module/lib/web3/ethereum.d.ts +96 -0
  153. package/dist/module/lib/web3/ethereum.d.ts.map +1 -0
  154. package/dist/module/lib/web3/ethereum.js +60 -0
  155. package/dist/module/lib/web3/ethereum.js.map +1 -0
  156. package/dist/module/lib/web3/solana.d.ts +160 -0
  157. package/dist/module/lib/web3/solana.d.ts.map +1 -0
  158. package/dist/module/lib/web3/solana.js +3 -0
  159. package/dist/module/lib/web3/solana.js.map +1 -0
  160. package/dist/module/lib/webauthn.d.ts +276 -0
  161. package/dist/module/lib/webauthn.d.ts.map +1 -0
  162. package/dist/module/lib/webauthn.dom.d.ts +583 -0
  163. package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
  164. package/dist/module/lib/webauthn.dom.js +3 -0
  165. package/dist/module/lib/webauthn.dom.js.map +1 -0
  166. package/dist/module/lib/webauthn.errors.d.ts +80 -0
  167. package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
  168. package/dist/module/lib/webauthn.errors.js +257 -0
  169. package/dist/module/lib/webauthn.errors.js.map +1 -0
  170. package/dist/module/lib/webauthn.js +689 -0
  171. package/dist/module/lib/webauthn.js.map +1 -0
  172. package/dist/tsconfig.module.tsbuildinfo +1 -0
  173. package/dist/tsconfig.tsbuildinfo +1 -0
  174. package/package.json +56 -0
  175. package/src/AuthAdminApi.ts +5 -0
  176. package/src/AuthClient.ts +5 -0
  177. package/src/GoTrueAdminApi.ts +723 -0
  178. package/src/GoTrueClient.ts +4078 -0
  179. package/src/index.ts +13 -0
  180. package/src/lib/base64url.ts +308 -0
  181. package/src/lib/constants.ts +34 -0
  182. package/src/lib/error-codes.ts +90 -0
  183. package/src/lib/errors.ts +324 -0
  184. package/src/lib/fetch.ts +283 -0
  185. package/src/lib/helpers.ts +463 -0
  186. package/src/lib/local-storage.ts +21 -0
  187. package/src/lib/locks.ts +375 -0
  188. package/src/lib/polyfills.ts +23 -0
  189. package/src/lib/types.ts +2229 -0
  190. package/src/lib/version.ts +7 -0
  191. package/src/lib/web3/ethereum.ts +184 -0
  192. package/src/lib/web3/solana.ts +186 -0
  193. package/src/lib/webauthn.dom.ts +636 -0
  194. package/src/lib/webauthn.errors.ts +317 -0
  195. package/src/lib/webauthn.ts +946 -0
@@ -0,0 +1,2229 @@
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. Use the `custom:` prefix for custom OIDC providers (e.g. `custom:my-oidc-provider`). */
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
+ /** Uses OAuth 1.0a */
38
+ | 'twitter'
39
+ /** Uses OAuth 2.0 */
40
+ | 'x'
41
+ | 'workos'
42
+ | 'zoom'
43
+ | 'fly'
44
+ | `custom:${string}`
45
+
46
+ export type AuthChangeEventMFA = 'MFA_CHALLENGE_VERIFIED'
47
+
48
+ export type AuthChangeEvent =
49
+ | 'INITIAL_SESSION'
50
+ | 'PASSWORD_RECOVERY'
51
+ | 'SIGNED_IN'
52
+ | 'SIGNED_OUT'
53
+ | 'TOKEN_REFRESHED'
54
+ | 'USER_UPDATED'
55
+ | AuthChangeEventMFA
56
+
57
+ /**
58
+ * Provide your own global lock implementation instead of the default
59
+ * implementation. The function should acquire a lock for the duration of the
60
+ * `fn` async function, such that no other client instances will be able to
61
+ * hold it at the same time.
62
+ *
63
+ * @experimental
64
+ *
65
+ * @param name Name of the lock to be acquired.
66
+ * @param acquireTimeout If negative, no timeout should occur. If positive it
67
+ * should throw an Error with an `isAcquireTimeout`
68
+ * property set to true if the operation fails to be
69
+ * acquired after this much time (ms).
70
+ * @param fn The operation to execute when the lock is acquired.
71
+ */
72
+ export type LockFunc = <R>(name: string, acquireTimeout: number, fn: () => Promise<R>) => Promise<R>
73
+
74
+ export type GoTrueClientOptions = {
75
+ /* The URL of the GoTrue server. */
76
+ url?: string
77
+ /* Any additional headers to send to the GoTrue server. */
78
+ headers?: { [key: string]: string }
79
+ /* Optional key name used for storing tokens in local storage. */
80
+ storageKey?: string
81
+ /**
82
+ * Set to "true" if you want to automatically detect OAuth grants in the URL and sign in the user.
83
+ * Set to "false" to disable automatic detection.
84
+ * Set to a function to provide custom logic for determining if a URL contains a Supabase auth callback.
85
+ * The function receives the current URL and parsed parameters, and should return true if the URL
86
+ * should be processed as a Supabase auth callback, or false to ignore it.
87
+ *
88
+ * This is useful when your app uses other OAuth providers (e.g., Facebook Login) that also return
89
+ * access_token in the URL fragment, which would otherwise be incorrectly intercepted by Supabase Auth.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * detectSessionInUrl: (url, params) => {
94
+ * // Ignore Facebook OAuth redirects
95
+ * if (url.pathname === '/facebook/redirect') return false
96
+ * // Use default detection for other URLs
97
+ * return Boolean(params.access_token || params.error_description)
98
+ * }
99
+ * ```
100
+ */
101
+ detectSessionInUrl?: boolean | ((url: URL, params: { [parameter: string]: string }) => boolean)
102
+ /* Set to "true" if you want to automatically refresh the token before expiring. */
103
+ autoRefreshToken?: boolean
104
+ /* 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. */
105
+ persistSession?: boolean
106
+ /* Provide your own local storage implementation to use instead of the browser's local storage. */
107
+ storage?: SupportedStorage
108
+ /**
109
+ * 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'`.
110
+ *
111
+ * 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.
112
+ *
113
+ * @experimental
114
+ */
115
+ userStorage?: SupportedStorage
116
+ /* A custom fetch implementation. */
117
+ fetch?: Fetch
118
+ /* If set to 'pkce' PKCE flow. Defaults to the 'implicit' flow otherwise */
119
+ flowType?: AuthFlowType
120
+ /* 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. */
121
+ debug?: boolean | ((message: string, ...args: any[]) => void)
122
+ /**
123
+ * Provide your own locking mechanism based on the environment. By default,
124
+ * `navigatorLock` (Web Locks API) is used in browser environments when
125
+ * `persistSession` is true. Falls back to an in-process lock for non-browser
126
+ * environments (e.g. React Native).
127
+ *
128
+ * @experimental
129
+ */
130
+ lock?: LockFunc
131
+ /**
132
+ * Set to "true" if there is a custom authorization header set globally.
133
+ * @experimental
134
+ */
135
+ hasCustomAuthorizationHeader?: boolean
136
+ /**
137
+ * If there is an error with the query, throwOnError will reject the promise by
138
+ * throwing the error instead of returning it as part of a successful response.
139
+ */
140
+ throwOnError?: boolean
141
+ /**
142
+ * The maximum time in milliseconds to wait for acquiring a cross-tab synchronization lock.
143
+ *
144
+ * When multiple browser tabs or windows use the auth client simultaneously, they coordinate
145
+ * via the Web Locks API to prevent race conditions during session refresh and other operations.
146
+ * This timeout controls how long to wait before attempting lock recovery.
147
+ *
148
+ * - **Positive value**: Wait up to this many milliseconds. If the lock is still held, attempt
149
+ * automatic recovery by stealing it (the previous holder is evicted, its callback continues
150
+ * to completion without exclusive access). This recovers from orphaned locks caused by
151
+ * React Strict Mode double-mount, storage API hangs, or aborted operations.
152
+ * - **Zero (0)**: Fail immediately if the lock is unavailable; throws `LockAcquireTimeoutError`
153
+ * (check `error.isAcquireTimeout === true`).
154
+ * - **Negative value**: Wait indefinitely — can cause permanent deadlocks if the lock is orphaned.
155
+ *
156
+ * @default 5000
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * const client = createClient(url, key, {
161
+ * auth: {
162
+ * lockAcquireTimeout: 5000, // 5 seconds, then steal orphaned lock
163
+ * },
164
+ * })
165
+ * ```
166
+ */
167
+ lockAcquireTimeout?: number
168
+
169
+ /**
170
+ * If true, skips automatic initialization in constructor. Useful for SSR
171
+ * contexts where initialization timing must be controlled to prevent race
172
+ * conditions with HTTP response generation.
173
+ *
174
+ * @default false
175
+ */
176
+ skipAutoInitialize?: boolean
177
+ }
178
+
179
+ const WeakPasswordReasons = ['length', 'characters', 'pwned'] as const
180
+
181
+ export type WeakPasswordReasons = (typeof WeakPasswordReasons)[number]
182
+ export type WeakPassword = {
183
+ reasons: WeakPasswordReasons[]
184
+ message: string
185
+ }
186
+
187
+ /**
188
+ * Resolve mapped types and show the derived keys and their types when hovering in
189
+ * VS Code, instead of just showing the names those mapped types are defined with.
190
+ */
191
+ export type Prettify<T> = T extends Function ? T : { [K in keyof T]: T[K] }
192
+
193
+ /**
194
+ * A stricter version of TypeScript's Omit that only allows omitting keys that actually exist.
195
+ * This prevents typos and ensures type safety at compile time.
196
+ * Unlike regular Omit, this will error if you try to omit a non-existent key.
197
+ */
198
+ export type StrictOmit<T, K extends keyof T> = Omit<T, K>
199
+
200
+ /**
201
+ * a shared result type that encapsulates errors instead of throwing them, allows you to optionally specify the ErrorType
202
+ */
203
+ export type RequestResult<T, ErrorType extends Error = AuthError> =
204
+ | {
205
+ data: T
206
+ error: null
207
+ }
208
+ | {
209
+ data: null
210
+ error: Error extends AuthError ? AuthError : ErrorType
211
+ }
212
+
213
+ /**
214
+ * similar to RequestResult except it allows you to destructure the possible shape of the success response
215
+ * {@see RequestResult}
216
+ */
217
+ export type RequestResultSafeDestructure<T> =
218
+ | { data: T; error: null }
219
+ | {
220
+ data: T extends object ? { [K in keyof T]: null } : null
221
+ error: AuthError
222
+ }
223
+
224
+ export type AuthResponse = RequestResultSafeDestructure<{
225
+ user: User | null
226
+ session: Session | null
227
+ }>
228
+
229
+ export type AuthResponsePassword = RequestResultSafeDestructure<{
230
+ user: User | null
231
+ session: Session | null
232
+ weak_password?: WeakPassword | null
233
+ }>
234
+
235
+ /**
236
+ * AuthOtpResponse is returned when OTP is used.
237
+ *
238
+ * {@see AuthResponse}
239
+ */
240
+ export type AuthOtpResponse = RequestResultSafeDestructure<{
241
+ user: null
242
+ session: null
243
+ messageId?: string | null
244
+ }>
245
+
246
+ export type AuthTokenResponse = RequestResultSafeDestructure<{
247
+ user: User
248
+ session: Session
249
+ }>
250
+
251
+ export type AuthTokenResponsePassword = RequestResultSafeDestructure<{
252
+ user: User
253
+ session: Session
254
+ weakPassword?: WeakPassword
255
+ }>
256
+
257
+ export type OAuthResponse =
258
+ | {
259
+ data: {
260
+ provider: Provider
261
+ url: string
262
+ }
263
+ error: null
264
+ }
265
+ | {
266
+ data: {
267
+ provider: Provider
268
+ url: null
269
+ }
270
+ error: AuthError
271
+ }
272
+
273
+ export type SSOResponse = RequestResult<{
274
+ /**
275
+ * URL to open in a browser which will complete the sign-in flow by
276
+ * taking the user to the identity provider's authentication flow.
277
+ *
278
+ * On browsers you can set the URL to `window.location.href` to take
279
+ * the user to the authentication flow.
280
+ */
281
+ url: string
282
+ }>
283
+
284
+ export type UserResponse = RequestResultSafeDestructure<{
285
+ user: User
286
+ }>
287
+
288
+ export interface Session {
289
+ /**
290
+ * The oauth provider token. If present, this can be used to make external API requests to the oauth provider used.
291
+ */
292
+ provider_token?: string | null
293
+ /**
294
+ * The oauth provider refresh token. If present, this can be used to refresh the provider_token via the oauth provider's API.
295
+ * 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.
296
+ */
297
+ provider_refresh_token?: string | null
298
+ /**
299
+ * The access token jwt. It is recommended to set the JWT_EXPIRY to a shorter expiry value.
300
+ */
301
+ access_token: string
302
+ /**
303
+ * A one-time used refresh token that never expires.
304
+ */
305
+ refresh_token: string
306
+ /**
307
+ * The number of seconds until the token expires (since it was issued). Returned when a login is confirmed.
308
+ */
309
+ expires_in: number
310
+ /**
311
+ * A timestamp of when the token will expire. Returned when a login is confirmed.
312
+ */
313
+ expires_at?: number
314
+ token_type: 'bearer'
315
+
316
+ /**
317
+ * When using a separate user storage, accessing properties of this object will throw an error.
318
+ */
319
+ user: User
320
+ }
321
+
322
+ const AMRMethods = [
323
+ 'password',
324
+ 'otp',
325
+ 'oauth',
326
+ 'totp',
327
+ 'mfa/totp',
328
+ 'mfa/phone',
329
+ 'mfa/webauthn',
330
+ 'anonymous',
331
+ 'sso/saml',
332
+ 'magiclink',
333
+ 'web3',
334
+ 'oauth_provider/authorization_code',
335
+ ] as const
336
+
337
+ export type AMRMethod = (typeof AMRMethods)[number] | (string & {})
338
+
339
+ /**
340
+ * An authentication method reference (AMR) entry.
341
+ *
342
+ * An entry designates what method was used by the user to verify their
343
+ * identity and at what time.
344
+ *
345
+ * Note: Custom access token hooks can return AMR claims as either:
346
+ * - An array of AMREntry objects (detailed format with timestamps)
347
+ * - An array of strings (RFC-8176 compliant format)
348
+ *
349
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}.
350
+ */
351
+ export interface AMREntry {
352
+ /** Authentication method name. */
353
+ method: AMRMethod
354
+
355
+ /**
356
+ * Timestamp when the method was successfully used. Represents number of
357
+ * seconds since 1st January 1970 (UNIX epoch) in UTC.
358
+ */
359
+ timestamp: number
360
+ }
361
+
362
+ export interface UserIdentity {
363
+ id: string
364
+ user_id: string
365
+ identity_data?: {
366
+ [key: string]: any
367
+ }
368
+ identity_id: string
369
+ provider: string
370
+ created_at?: string
371
+ last_sign_in_at?: string
372
+ updated_at?: string
373
+ }
374
+
375
+ const FactorTypes = ['totp', 'phone', 'webauthn'] as const
376
+
377
+ /**
378
+ * Type of factor. `totp` and `phone` supported with this version
379
+ */
380
+ export type FactorType = (typeof FactorTypes)[number]
381
+
382
+ const FactorVerificationStatuses = ['verified', 'unverified'] as const
383
+
384
+ /**
385
+ * The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
386
+ */
387
+ type FactorVerificationStatus = (typeof FactorVerificationStatuses)[number]
388
+
389
+ /**
390
+ * A MFA factor.
391
+ *
392
+ * @see {@link GoTrueMFAApi#enroll}
393
+ * @see {@link GoTrueMFAApi#listFactors}
394
+ * @see {@link GoTrueMFAAdminApi#listFactors}
395
+ */
396
+ export type Factor<
397
+ Type extends FactorType = FactorType,
398
+ Status extends FactorVerificationStatus = (typeof FactorVerificationStatuses)[number],
399
+ > = {
400
+ /** ID of the factor. */
401
+ id: string
402
+
403
+ /** Friendly name of the factor, useful to disambiguate between multiple factors. */
404
+ friendly_name?: string
405
+
406
+ /**
407
+ * Type of factor. `totp` and `phone` supported with this version
408
+ */
409
+ factor_type: Type
410
+
411
+ /**
412
+ * The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
413
+ */
414
+ status: Status
415
+
416
+ created_at: string
417
+ updated_at: string
418
+ last_challenged_at?: string
419
+ }
420
+
421
+ export interface UserAppMetadata {
422
+ /**
423
+ * The first provider that the user used to sign up with.
424
+ */
425
+ provider?: string
426
+ /**
427
+ * A list of all providers that the user has linked to their account.
428
+ */
429
+ providers?: string[]
430
+ [key: string]: any
431
+ }
432
+
433
+ export interface UserMetadata {
434
+ [key: string]: any
435
+ }
436
+
437
+ export interface User {
438
+ id: string
439
+ app_metadata: UserAppMetadata
440
+ user_metadata: UserMetadata
441
+ aud: string
442
+ confirmation_sent_at?: string
443
+ recovery_sent_at?: string
444
+ email_change_sent_at?: string
445
+ new_email?: string
446
+ new_phone?: string
447
+ invited_at?: string
448
+ action_link?: string
449
+ email?: string
450
+ phone?: string
451
+ created_at: string
452
+ confirmed_at?: string
453
+ email_confirmed_at?: string
454
+ phone_confirmed_at?: string
455
+ last_sign_in_at?: string
456
+ role?: string
457
+ updated_at?: string
458
+ identities?: UserIdentity[]
459
+ is_anonymous?: boolean
460
+ is_sso_user?: boolean
461
+ factors?: (Factor<FactorType, 'verified'> | Factor<FactorType, 'unverified'>)[]
462
+ deleted_at?: string
463
+ banned_until?: string
464
+ }
465
+
466
+ export interface UserAttributes {
467
+ /**
468
+ * The user's current password
469
+ *
470
+ * This is only ever present when the user is resetting
471
+ * their password and GOTRUE_SECURITY_UPDATE_PASSWORD_REQUIRE_CURRENT_PASSWORD is true.
472
+ *
473
+ */
474
+ current_password?: string
475
+
476
+ /**
477
+ * The user's email.
478
+ */
479
+ email?: string
480
+
481
+ /**
482
+ * The user's phone.
483
+ */
484
+ phone?: string
485
+
486
+ /**
487
+ * The user's password.
488
+ */
489
+ password?: string
490
+
491
+ /**
492
+ * The nonce sent for reauthentication if the user's password is to be updated.
493
+ *
494
+ * Call reauthenticate() to obtain the nonce first.
495
+ */
496
+ nonce?: string
497
+
498
+ /**
499
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
500
+ *
501
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
502
+ *
503
+ */
504
+ data?: object
505
+ }
506
+
507
+ export interface AdminUserAttributes extends Omit<UserAttributes, 'data'> {
508
+ /**
509
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
510
+ *
511
+ *
512
+ * The `user_metadata` should be a JSON object that includes user-specific info, such as their first and last name.
513
+ *
514
+ * Note: When using the GoTrueAdminApi and wanting to modify a user's metadata,
515
+ * this attribute is used instead of UserAttributes data.
516
+ *
517
+ */
518
+ user_metadata?: object
519
+
520
+ /**
521
+ * A custom data object to store the user's application specific metadata. This maps to the `auth.users.app_metadata` column.
522
+ *
523
+ * Only a service role can modify.
524
+ *
525
+ * The `app_metadata` should be a JSON object that includes app-specific info, such as identity providers, roles, and other
526
+ * access control information.
527
+ */
528
+ app_metadata?: object
529
+
530
+ /**
531
+ * Sets the user's email as confirmed when true, or unconfirmed when false.
532
+ *
533
+ * Only a service role can modify.
534
+ */
535
+ email_confirm?: boolean
536
+
537
+ /**
538
+ * Sets the user's phone as confirmed when true, or unconfirmed when false.
539
+ *
540
+ * Only a service role can modify.
541
+ */
542
+ phone_confirm?: boolean
543
+
544
+ /**
545
+ * Determines how long a user is banned for.
546
+ *
547
+ * The format for the ban duration follows a strict sequence of decimal numbers with a unit suffix.
548
+ * Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
549
+ *
550
+ * For example, some possible durations include: '300ms', '2h45m'.
551
+ *
552
+ * Setting the ban duration to 'none' lifts the ban on the user.
553
+ */
554
+ ban_duration?: string | 'none'
555
+
556
+ /**
557
+ * The `role` claim set in the user's access token JWT.
558
+ *
559
+ * 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.
560
+ *
561
+ * Setting this role to `service_role` is not recommended as it grants the user admin privileges.
562
+ */
563
+ role?: string
564
+
565
+ /**
566
+ * The `password_hash` for the user's password.
567
+ *
568
+ * Allows you to specify a password hash for the user. This is useful for migrating a user's password hash from another service.
569
+ *
570
+ * Supports bcrypt, scrypt (firebase), and argon2 password hashes.
571
+ */
572
+ password_hash?: string
573
+
574
+ /**
575
+ * The `id` for the user.
576
+ *
577
+ * Allows you to overwrite the default `id` set for the user.
578
+ */
579
+ id?: string
580
+ }
581
+
582
+ export interface Subscription {
583
+ /**
584
+ * A unique identifier for this subscription, set by the client.
585
+ * This is an internal identifier used for managing callbacks and should not be
586
+ * relied upon by application code. Use the unsubscribe() method to remove listeners.
587
+ */
588
+ id: string | symbol
589
+ /**
590
+ * The function to call every time there is an event. eg: (eventName) => {}
591
+ */
592
+ callback: (event: AuthChangeEvent, session: Session | null) => void
593
+ /**
594
+ * Call this to remove the listener.
595
+ */
596
+ unsubscribe: () => void
597
+ }
598
+
599
+ export type SignInAnonymouslyCredentials = {
600
+ options?: {
601
+ /**
602
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
603
+ *
604
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
605
+ */
606
+ data?: object
607
+ /** Verification token received when the user completes the captcha on the site. */
608
+ captchaToken?: string
609
+ }
610
+ }
611
+
612
+ export type SignUpWithPasswordCredentials = Prettify<
613
+ PasswordCredentialsBase & {
614
+ options?: {
615
+ emailRedirectTo?: string // only for email
616
+ data?: object
617
+ captchaToken?: string
618
+ channel?: 'sms' | 'whatsapp' // only for phone
619
+ }
620
+ }
621
+ >
622
+
623
+ type PasswordCredentialsBase =
624
+ | { email: string; password: string }
625
+ | { phone: string; password: string }
626
+
627
+ export type SignInWithPasswordCredentials = PasswordCredentialsBase & {
628
+ options?: {
629
+ captchaToken?: string
630
+ }
631
+ }
632
+
633
+ export type SignInWithPasswordlessCredentials =
634
+ | {
635
+ /** The user's email address. */
636
+ email: string
637
+ options?: {
638
+ /** The redirect url embedded in the email link */
639
+ emailRedirectTo?: string
640
+ /** If set to false, this method will not create a new user. Defaults to true. */
641
+ shouldCreateUser?: boolean
642
+ /**
643
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
644
+ *
645
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
646
+ */
647
+ data?: object
648
+ /** Verification token received when the user completes the captcha on the site. */
649
+ captchaToken?: string
650
+ }
651
+ }
652
+ | {
653
+ /** The user's phone number. */
654
+ phone: string
655
+ options?: {
656
+ /** If set to false, this method will not create a new user. Defaults to true. */
657
+ shouldCreateUser?: boolean
658
+ /**
659
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
660
+ *
661
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
662
+ */
663
+ data?: object
664
+ /** Verification token received when the user completes the captcha on the site. */
665
+ captchaToken?: string
666
+ /** Messaging channel to use (e.g. whatsapp or sms) */
667
+ channel?: 'sms' | 'whatsapp'
668
+ }
669
+ }
670
+
671
+ export type AuthFlowType = 'implicit' | 'pkce'
672
+ export type SignInWithOAuthCredentials = {
673
+ /** One of the providers supported by GoTrue. */
674
+ provider: Provider
675
+ options?: {
676
+ /** A URL to send the user to after they are confirmed. */
677
+ redirectTo?: string
678
+ /** A space-separated list of scopes granted to the OAuth application. */
679
+ scopes?: string
680
+ /** An object of query params */
681
+ queryParams?: { [key: string]: string }
682
+ /** If set to true does not immediately redirect the current browser context to visit the OAuth authorization page for the provider. */
683
+ skipBrowserRedirect?: boolean
684
+ }
685
+ }
686
+
687
+ export type SignInWithIdTokenCredentials = {
688
+ /** Provider name or OIDC `iss` value identifying which provider should be used to verify the provided token. Supported names: `google`, `apple`, `azure`, `facebook`, `kakao`. Use the `custom:` prefix for custom OIDC providers (e.g. `custom:my-oidc-provider`). */
689
+ provider: 'google' | 'apple' | 'azure' | 'facebook' | 'kakao' | `custom:${string}` | (string & {})
690
+ /** 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. */
691
+ token: string
692
+ /** If the ID token contains an `at_hash` claim, then the hash of this value is compared to the value in the ID token. */
693
+ access_token?: string
694
+ /** If the ID token contains a `nonce` claim, then the hash of this value is compared to the value in the ID token. */
695
+ nonce?: string
696
+ options?: {
697
+ /** Verification token received when the user completes the captcha on the site. */
698
+ captchaToken?: string
699
+ }
700
+ }
701
+
702
+ export type SolanaWallet = {
703
+ signIn?: (...inputs: SolanaSignInInput[]) => Promise<SolanaSignInOutput | SolanaSignInOutput[]>
704
+ publicKey?: {
705
+ toBase58: () => string
706
+ } | null
707
+
708
+ signMessage?: (message: Uint8Array, encoding?: 'utf8' | string) => Promise<Uint8Array> | undefined
709
+ }
710
+
711
+ export type SolanaWeb3Credentials =
712
+ | {
713
+ chain: 'solana'
714
+
715
+ /** Wallet interface to use. If not specified will default to `window.solana`. */
716
+ wallet?: SolanaWallet
717
+
718
+ /** 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!** */
719
+ statement?: string
720
+
721
+ options?: {
722
+ /** URL to use with the wallet interface. Some wallets do not allow signing a message for URLs different from the current page. */
723
+ url?: string
724
+
725
+ /** Verification token received when the user completes the captcha on the site. */
726
+ captchaToken?: string
727
+
728
+ signInWithSolana?: Partial<
729
+ Omit<SolanaSignInInput, 'version' | 'chain' | 'domain' | 'uri' | 'statement'>
730
+ >
731
+ }
732
+ }
733
+ | {
734
+ chain: 'solana'
735
+
736
+ /** Sign in with Solana compatible message. Must include `Issued At`, `URI` and `Version`. */
737
+ message: string
738
+
739
+ /** Ed25519 signature of the message. */
740
+ signature: Uint8Array
741
+
742
+ options?: {
743
+ /** Verification token received when the user completes the captcha on the site. */
744
+ captchaToken?: string
745
+ }
746
+ }
747
+
748
+ export type EthereumWallet = EIP1193Provider
749
+
750
+ export type EthereumWeb3Credentials =
751
+ | {
752
+ chain: 'ethereum'
753
+
754
+ /** Wallet interface to use. If not specified will default to `window.ethereum`. */
755
+ wallet?: EthereumWallet
756
+
757
+ /** 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!** */
758
+ statement?: string
759
+
760
+ options?: {
761
+ /** URL to use with the wallet interface. Some wallets do not allow signing a message for URLs different from the current page. */
762
+ url?: string
763
+
764
+ /** Verification token received when the user completes the captcha on the site. */
765
+ captchaToken?: string
766
+
767
+ signInWithEthereum?: Partial<
768
+ Omit<EthereumSignInInput, 'version' | 'domain' | 'uri' | 'statement'>
769
+ >
770
+ }
771
+ }
772
+ | {
773
+ chain: 'ethereum'
774
+
775
+ /** Sign in with Ethereum compatible message. Must include `Issued At`, `URI` and `Version`. */
776
+ message: string
777
+
778
+ /** Ethereum curve (secp256k1) signature of the message. */
779
+ signature: Hex
780
+
781
+ options?: {
782
+ /** Verification token received when the user completes the captcha on the site. */
783
+ captchaToken?: string
784
+ }
785
+ }
786
+
787
+ export type Web3Credentials = SolanaWeb3Credentials | EthereumWeb3Credentials
788
+
789
+ export type VerifyOtpParams = VerifyMobileOtpParams | VerifyEmailOtpParams | VerifyTokenHashParams
790
+ export interface VerifyMobileOtpParams {
791
+ /** The user's phone number. */
792
+ phone: string
793
+ /** The otp sent to the user's phone number. */
794
+ token: string
795
+ /** The user's verification type. */
796
+ type: MobileOtpType
797
+ options?: {
798
+ /** A URL to send the user to after they are confirmed. */
799
+ redirectTo?: string
800
+
801
+ /**
802
+ * Verification token received when the user completes the captcha on the site.
803
+ *
804
+ * @deprecated
805
+ */
806
+ captchaToken?: string
807
+ }
808
+ }
809
+ export interface VerifyEmailOtpParams {
810
+ /** The user's email address. */
811
+ email: string
812
+ /** The otp sent to the user's email address. */
813
+ token: string
814
+ /** The user's verification type. */
815
+ type: EmailOtpType
816
+ options?: {
817
+ /** A URL to send the user to after they are confirmed. */
818
+ redirectTo?: string
819
+
820
+ /** Verification token received when the user completes the captcha on the site.
821
+ *
822
+ * @deprecated
823
+ */
824
+ captchaToken?: string
825
+ }
826
+ }
827
+
828
+ export interface VerifyTokenHashParams {
829
+ /** The token hash used in an email link */
830
+ token_hash: string
831
+
832
+ /** The user's verification type. */
833
+ type: EmailOtpType
834
+ }
835
+
836
+ export type MobileOtpType = 'sms' | 'phone_change'
837
+ export type EmailOtpType = 'signup' | 'invite' | 'magiclink' | 'recovery' | 'email_change' | 'email'
838
+
839
+ export type ResendParams =
840
+ | {
841
+ type: Extract<EmailOtpType, 'signup' | 'email_change'>
842
+ email: string
843
+ options?: {
844
+ /** A URL to send the user to after they have signed-in. */
845
+ emailRedirectTo?: string
846
+ /** Verification token received when the user completes the captcha on the site. */
847
+ captchaToken?: string
848
+ }
849
+ }
850
+ | {
851
+ type: Extract<MobileOtpType, 'sms' | 'phone_change'>
852
+ phone: string
853
+ options?: {
854
+ /** Verification token received when the user completes the captcha on the site. */
855
+ captchaToken?: string
856
+ }
857
+ }
858
+
859
+ export type SignInWithSSO =
860
+ | {
861
+ /** UUID of the SSO provider to invoke single-sign on to. */
862
+ providerId: string
863
+
864
+ options?: {
865
+ /** A URL to send the user to after they have signed-in. */
866
+ redirectTo?: string
867
+ /** Verification token received when the user completes the captcha on the site. */
868
+ captchaToken?: string
869
+ /**
870
+ * If set to true, the redirect will not happen on the client side.
871
+ * This parameter is used when you wish to handle the redirect yourself.
872
+ * Defaults to false.
873
+ */
874
+ skipBrowserRedirect?: boolean
875
+ }
876
+ }
877
+ | {
878
+ /** Domain name of the organization for which to invoke single-sign on. */
879
+ domain: string
880
+
881
+ options?: {
882
+ /** A URL to send the user to after they have signed-in. */
883
+ redirectTo?: string
884
+ /** Verification token received when the user completes the captcha on the site. */
885
+ captchaToken?: string
886
+ /**
887
+ * If set to true, the redirect will not happen on the client side.
888
+ * This parameter is used when you wish to handle the redirect yourself.
889
+ * Defaults to false.
890
+ */
891
+ skipBrowserRedirect?: boolean
892
+ }
893
+ }
894
+
895
+ export type GenerateSignupLinkParams = {
896
+ type: 'signup'
897
+ email: string
898
+ password: string
899
+ options?: Pick<GenerateLinkOptions, 'data' | 'redirectTo'>
900
+ }
901
+
902
+ export type GenerateInviteOrMagiclinkParams = {
903
+ type: 'invite' | 'magiclink'
904
+ /** The user's email */
905
+ email: string
906
+ options?: Pick<GenerateLinkOptions, 'data' | 'redirectTo'>
907
+ }
908
+
909
+ export type GenerateRecoveryLinkParams = {
910
+ type: 'recovery'
911
+ /** The user's email */
912
+ email: string
913
+ options?: Pick<GenerateLinkOptions, 'redirectTo'>
914
+ }
915
+
916
+ export type GenerateEmailChangeLinkParams = {
917
+ type: 'email_change_current' | 'email_change_new'
918
+ /** The user's email */
919
+ email: string
920
+ /**
921
+ * The user's new email. Only required if type is 'email_change_current' or 'email_change_new'.
922
+ */
923
+ newEmail: string
924
+ options?: Pick<GenerateLinkOptions, 'redirectTo'>
925
+ }
926
+
927
+ export interface GenerateLinkOptions {
928
+ /**
929
+ * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
930
+ *
931
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
932
+ */
933
+ data?: object
934
+ /** The URL which will be appended to the email link generated. */
935
+ redirectTo?: string
936
+ }
937
+
938
+ export type GenerateLinkParams =
939
+ | GenerateSignupLinkParams
940
+ | GenerateInviteOrMagiclinkParams
941
+ | GenerateRecoveryLinkParams
942
+ | GenerateEmailChangeLinkParams
943
+
944
+ export type GenerateLinkResponse = RequestResultSafeDestructure<{
945
+ properties: GenerateLinkProperties
946
+ user: User
947
+ }>
948
+
949
+ /** The properties related to the email link generated */
950
+ export type GenerateLinkProperties = {
951
+ /**
952
+ * The email link to send to the user.
953
+ * The action_link follows the following format: auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
954
+ * */
955
+ action_link: string
956
+ /**
957
+ * The raw email OTP.
958
+ * You should send this in the email if you want your users to verify using an OTP instead of the action link.
959
+ * */
960
+ email_otp: string
961
+ /**
962
+ * The hashed token appended to the action link.
963
+ * */
964
+ hashed_token: string
965
+ /** The URL appended to the action link. */
966
+ redirect_to: string
967
+ /** The verification type that the email link is associated to. */
968
+ verification_type: GenerateLinkType
969
+ }
970
+
971
+ export type GenerateLinkType =
972
+ | 'signup'
973
+ | 'invite'
974
+ | 'magiclink'
975
+ | 'recovery'
976
+ | 'email_change_current'
977
+ | 'email_change_new'
978
+
979
+ export type MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams | MFAEnrollWebauthnParams
980
+
981
+ export type MFAUnenrollParams = {
982
+ /** ID of the factor being unenrolled. */
983
+ factorId: string
984
+ }
985
+
986
+ type MFAVerifyParamsBase = {
987
+ /** ID of the factor being verified. Returned in enroll(). */
988
+ factorId: string
989
+ /** ID of the challenge being verified. Returned in challenge(). */
990
+ challengeId: string
991
+ }
992
+
993
+ type MFAVerifyTOTPParamFields = {
994
+ /** Verification code provided by the user. */
995
+ code: string
996
+ }
997
+
998
+ export type MFAVerifyTOTPParams = Prettify<MFAVerifyParamsBase & MFAVerifyTOTPParamFields>
999
+
1000
+ type MFAVerifyPhoneParamFields = MFAVerifyTOTPParamFields
1001
+
1002
+ export type MFAVerifyPhoneParams = Prettify<MFAVerifyParamsBase & MFAVerifyPhoneParamFields>
1003
+
1004
+ type MFAVerifyWebauthnParamFieldsBase = {
1005
+ /** Relying party ID */
1006
+ rpId: string
1007
+ /** Relying party origins */
1008
+ rpOrigins?: string[]
1009
+ }
1010
+
1011
+ type MFAVerifyWebauthnCredentialParamFields<T extends 'create' | 'request' = 'create' | 'request'> =
1012
+ {
1013
+ /** Operation type */
1014
+ type: T
1015
+ /** Creation response from the authenticator (for enrollment/unverified factors) */
1016
+ credential_response: T extends 'create' ? RegistrationCredential : AuthenticationCredential
1017
+ }
1018
+
1019
+ /**
1020
+ * WebAuthn-specific fields for MFA verification.
1021
+ * Supports both credential creation (registration) and request (authentication) flows.
1022
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
1023
+ */
1024
+ export type MFAVerifyWebauthnParamFields<T extends 'create' | 'request' = 'create' | 'request'> = {
1025
+ webauthn: MFAVerifyWebauthnParamFieldsBase & MFAVerifyWebauthnCredentialParamFields<T>
1026
+ }
1027
+
1028
+ /**
1029
+ * Parameters for WebAuthn MFA verification.
1030
+ * Used to verify WebAuthn credentials after challenge.
1031
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
1032
+ * @see {@link https://w3c.github.io/webauthn/#sctn-verifying-assertion W3C WebAuthn Spec - Verifying an Authentication Assertion}
1033
+ */
1034
+ export type MFAVerifyWebauthnParams<T extends 'create' | 'request' = 'create' | 'request'> =
1035
+ Prettify<MFAVerifyParamsBase & MFAVerifyWebauthnParamFields<T>>
1036
+
1037
+ export type MFAVerifyParams = MFAVerifyTOTPParams | MFAVerifyPhoneParams | MFAVerifyWebauthnParams
1038
+
1039
+ type MFAChallengeParamsBase = {
1040
+ /** ID of the factor to be challenged. Returned in enroll(). */
1041
+ factorId: string
1042
+ }
1043
+
1044
+ const MFATOTPChannels = ['sms', 'whatsapp'] as const
1045
+ export type MFATOTPChannel = (typeof MFATOTPChannels)[number]
1046
+
1047
+ export type MFAChallengeTOTPParams = Prettify<MFAChallengeParamsBase>
1048
+
1049
+ type MFAChallengePhoneParamFields<Channel extends MFATOTPChannel = MFATOTPChannel> = {
1050
+ /** Messaging channel to use (e.g. whatsapp or sms). Only relevant for phone factors */
1051
+ channel: Channel
1052
+ }
1053
+
1054
+ export type MFAChallengePhoneParams = Prettify<
1055
+ MFAChallengeParamsBase & MFAChallengePhoneParamFields
1056
+ >
1057
+
1058
+ /** WebAuthn parameters for WebAuthn factor challenge */
1059
+ type MFAChallengeWebauthnParamFields = {
1060
+ webauthn: {
1061
+ /** Relying party ID */
1062
+ rpId: string
1063
+ /** Relying party origins*/
1064
+ rpOrigins?: string[]
1065
+ }
1066
+ }
1067
+
1068
+ /**
1069
+ * Parameters for initiating a WebAuthn MFA challenge.
1070
+ * Includes Relying Party information needed for WebAuthn ceremonies.
1071
+ * @see {@link https://w3c.github.io/webauthn/#sctn-rp-operations W3C WebAuthn Spec - Relying Party Operations}
1072
+ */
1073
+ export type MFAChallengeWebauthnParams = Prettify<
1074
+ MFAChallengeParamsBase & MFAChallengeWebauthnParamFields
1075
+ >
1076
+
1077
+ export type MFAChallengeParams =
1078
+ | MFAChallengeTOTPParams
1079
+ | MFAChallengePhoneParams
1080
+ | MFAChallengeWebauthnParams
1081
+
1082
+ type MFAChallengeAndVerifyParamsBase = Omit<MFAVerifyParamsBase, 'challengeId'>
1083
+
1084
+ type MFAChallengeAndVerifyTOTPParamFields = MFAVerifyTOTPParamFields
1085
+
1086
+ type MFAChallengeAndVerifyTOTPParams = Prettify<
1087
+ MFAChallengeAndVerifyParamsBase & MFAChallengeAndVerifyTOTPParamFields
1088
+ >
1089
+
1090
+ export type MFAChallengeAndVerifyParams = MFAChallengeAndVerifyTOTPParams
1091
+
1092
+ /**
1093
+ * Data returned after successful MFA verification.
1094
+ * Contains new session tokens and updated user information.
1095
+ */
1096
+ export type AuthMFAVerifyResponseData = {
1097
+ /** New access token (JWT) after successful verification. */
1098
+ access_token: string
1099
+
1100
+ /** Type of token, always `bearer`. */
1101
+ token_type: 'bearer'
1102
+
1103
+ /** Number of seconds in which the access token will expire. */
1104
+ expires_in: number
1105
+
1106
+ /** Refresh token you can use to obtain new access tokens when expired. */
1107
+ refresh_token: string
1108
+
1109
+ /** Updated user profile. */
1110
+ user: User
1111
+ }
1112
+
1113
+ /**
1114
+ * Response type for MFA verification operations.
1115
+ * Returns session tokens on successful verification.
1116
+ */
1117
+ export type AuthMFAVerifyResponse = RequestResult<AuthMFAVerifyResponseData>
1118
+
1119
+ export type AuthMFAEnrollResponse =
1120
+ | AuthMFAEnrollTOTPResponse
1121
+ | AuthMFAEnrollPhoneResponse
1122
+ | AuthMFAEnrollWebauthnResponse
1123
+
1124
+ export type AuthMFAUnenrollResponse = RequestResult<{
1125
+ /** ID of the factor that was successfully unenrolled. */
1126
+ id: string
1127
+ }>
1128
+
1129
+ type AuthMFAChallengeResponseBase<T extends FactorType> = {
1130
+ /** ID of the newly created challenge. */
1131
+ id: string
1132
+
1133
+ /** Factor Type which generated the challenge */
1134
+ type: T
1135
+
1136
+ /** Timestamp in UNIX seconds when this challenge will no longer be usable. */
1137
+ expires_at: number
1138
+ }
1139
+
1140
+ type AuthMFAChallengeTOTPResponseFields = {
1141
+ /** no extra fields for now, kept for consistency and for possible future changes */
1142
+ }
1143
+
1144
+ export type AuthMFAChallengeTOTPResponse = RequestResult<
1145
+ Prettify<AuthMFAChallengeResponseBase<'totp'> & AuthMFAChallengeTOTPResponseFields>
1146
+ >
1147
+
1148
+ type AuthMFAChallengePhoneResponseFields = {
1149
+ /** no extra fields for now, kept for consistency and for possible future changes */
1150
+ }
1151
+
1152
+ export type AuthMFAChallengePhoneResponse = RequestResult<
1153
+ Prettify<AuthMFAChallengeResponseBase<'phone'> & AuthMFAChallengePhoneResponseFields>
1154
+ >
1155
+
1156
+ type AuthMFAChallengeWebauthnResponseFields = {
1157
+ webauthn:
1158
+ | {
1159
+ type: 'create'
1160
+ credential_options: { publicKey: PublicKeyCredentialCreationOptionsFuture }
1161
+ }
1162
+ | {
1163
+ type: 'request'
1164
+ credential_options: { publicKey: PublicKeyCredentialRequestOptionsFuture }
1165
+ }
1166
+ }
1167
+
1168
+ /**
1169
+ * Response type for WebAuthn MFA challenge.
1170
+ * Contains credential creation or request options from the server.
1171
+ * @see {@link https://w3c.github.io/webauthn/#sctn-credential-creation W3C WebAuthn Spec - Credential Creation}
1172
+ */
1173
+ export type AuthMFAChallengeWebauthnResponse = RequestResult<
1174
+ Prettify<AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFields>
1175
+ >
1176
+
1177
+ type AuthMFAChallengeWebauthnResponseFieldsJSON = {
1178
+ webauthn:
1179
+ | {
1180
+ type: 'create'
1181
+ credential_options: { publicKey: ServerCredentialCreationOptions }
1182
+ }
1183
+ | {
1184
+ type: 'request'
1185
+ credential_options: { publicKey: ServerCredentialRequestOptions }
1186
+ }
1187
+ }
1188
+
1189
+ /**
1190
+ * JSON-serializable version of WebAuthn challenge response.
1191
+ * Used for server communication with base64url-encoded binary fields.
1192
+ */
1193
+ export type AuthMFAChallengeWebauthnResponseDataJSON = Prettify<
1194
+ AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFieldsJSON
1195
+ >
1196
+
1197
+ /**
1198
+ * Server response type for WebAuthn MFA challenge.
1199
+ * Contains JSON-formatted WebAuthn options ready for browser API.
1200
+ */
1201
+ export type AuthMFAChallengeWebauthnServerResponse =
1202
+ RequestResult<AuthMFAChallengeWebauthnResponseDataJSON>
1203
+
1204
+ export type AuthMFAChallengeResponse =
1205
+ | AuthMFAChallengeTOTPResponse
1206
+ | AuthMFAChallengePhoneResponse
1207
+ | AuthMFAChallengeWebauthnResponse
1208
+
1209
+ /** response of ListFactors, which should contain all the types of factors that are available, this ensures we always include all */
1210
+ export type AuthMFAListFactorsResponse<T extends typeof FactorTypes = typeof FactorTypes> =
1211
+ RequestResult<
1212
+ {
1213
+ /** All available factors (verified and unverified). */
1214
+ all: Prettify<Factor>[]
1215
+
1216
+ // Dynamically create a property for each factor type with only verified factors
1217
+ } & {
1218
+ [K in T[number]]: Prettify<Factor<K, 'verified'>>[]
1219
+ }
1220
+ >
1221
+
1222
+ export type AuthenticatorAssuranceLevels = 'aal1' | 'aal2'
1223
+
1224
+ export type AuthMFAGetAuthenticatorAssuranceLevelResponse = RequestResult<{
1225
+ /** Current AAL level of the session. */
1226
+ currentLevel: AuthenticatorAssuranceLevels | null
1227
+
1228
+ /**
1229
+ * Next possible AAL level for the session. If the next level is higher
1230
+ * than the current one, the user should go through MFA.
1231
+ *
1232
+ * @see {@link GoTrueMFAApi#challenge}
1233
+ */
1234
+ nextLevel: AuthenticatorAssuranceLevels | null
1235
+
1236
+ /**
1237
+ * A list of all authentication methods attached to this session. Use
1238
+ * the information here to detect the last time a user verified a
1239
+ * factor, for example if implementing a step-up scenario.
1240
+ *
1241
+ * Supports both RFC-8176 compliant format (string[]) and detailed format (AMREntry[]).
1242
+ * - String format: ['password', 'otp'] - RFC-8176 compliant
1243
+ * - Object format: [{ method: 'password', timestamp: 1234567890 }] - includes timestamps
1244
+ */
1245
+ currentAuthenticationMethods: AMREntry[] | string[]
1246
+ }>
1247
+
1248
+ /**
1249
+ * Contains the full multi-factor authentication API.
1250
+ *
1251
+ */
1252
+ export interface GoTrueMFAApi {
1253
+ /**
1254
+ * Starts the enrollment process for a new Multi-Factor Authentication (MFA)
1255
+ * factor. This method creates a new `unverified` factor.
1256
+ * To verify a factor, present the QR code or secret to the user and ask them to add it to their
1257
+ * authenticator app.
1258
+ * The user has to enter the code from their authenticator app to verify it.
1259
+ *
1260
+ * Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to `aal2`.
1261
+ */
1262
+ enroll(params: MFAEnrollTOTPParams): Promise<AuthMFAEnrollTOTPResponse>
1263
+ enroll(params: MFAEnrollPhoneParams): Promise<AuthMFAEnrollPhoneResponse>
1264
+ enroll(params: MFAEnrollWebauthnParams): Promise<AuthMFAEnrollWebauthnResponse>
1265
+ enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse>
1266
+
1267
+ /**
1268
+ * Prepares a challenge used to verify that a user has access to a MFA
1269
+ * factor.
1270
+ */
1271
+ challenge(params: MFAChallengeTOTPParams): Promise<Prettify<AuthMFAChallengeTOTPResponse>>
1272
+ challenge(params: MFAChallengePhoneParams): Promise<Prettify<AuthMFAChallengePhoneResponse>>
1273
+ challenge(params: MFAChallengeWebauthnParams): Promise<Prettify<AuthMFAChallengeWebauthnResponse>>
1274
+ challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse>
1275
+
1276
+ /**
1277
+ * Verifies a code against a challenge. The verification code is
1278
+ * provided by the user by entering a code seen in their authenticator app.
1279
+ */
1280
+ verify(params: MFAVerifyTOTPParams): Promise<AuthMFAVerifyResponse>
1281
+ verify(params: MFAVerifyPhoneParams): Promise<AuthMFAVerifyResponse>
1282
+ verify(params: MFAVerifyWebauthnParams): Promise<AuthMFAVerifyResponse>
1283
+ verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>
1284
+
1285
+ /**
1286
+ * Unenroll removes a MFA factor.
1287
+ * A user has to have an `aal2` authenticator level in order to unenroll a `verified` factor.
1288
+ */
1289
+ unenroll(params: MFAUnenrollParams): Promise<AuthMFAUnenrollResponse>
1290
+
1291
+ /**
1292
+ * Helper method which creates a challenge and immediately uses the given code to verify against it thereafter. The verification code is
1293
+ * provided by the user by entering a code seen in their authenticator app.
1294
+ */
1295
+ challengeAndVerify(params: MFAChallengeAndVerifyParams): Promise<AuthMFAVerifyResponse>
1296
+
1297
+ /**
1298
+ * Returns the list of MFA factors enabled for this user.
1299
+ *
1300
+ * @see {@link GoTrueMFAApi#enroll}
1301
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}
1302
+ * @see {@link GoTrueClient#getUser}
1303
+ *
1304
+ */
1305
+ listFactors(): Promise<AuthMFAListFactorsResponse>
1306
+
1307
+ /**
1308
+ * Returns the Authenticator Assurance Level (AAL) for the active session.
1309
+ *
1310
+ * - `aal1` (or `null`) means that the user's identity has been verified only
1311
+ * with a conventional login (email+password, OTP, magic link, social login,
1312
+ * etc.).
1313
+ * - `aal2` means that the user's identity has been verified both with a conventional login and at least one MFA factor.
1314
+ *
1315
+ * When called without a JWT parameter, this method is fairly quick (microseconds)
1316
+ * and rarely uses the network. When a JWT is provided (useful in server-side
1317
+ * environments like Edge Functions where no session is stored), this method
1318
+ * will make a network request to validate the user and fetch their MFA factors.
1319
+ *
1320
+ * @param jwt Takes in an optional access token JWT. If no JWT is provided, the JWT from the current session is used.
1321
+ */
1322
+ getAuthenticatorAssuranceLevel(
1323
+ jwt?: string
1324
+ ): Promise<AuthMFAGetAuthenticatorAssuranceLevelResponse>
1325
+
1326
+ // namespace for the webauthn methods
1327
+ webauthn: WebAuthnApi
1328
+ }
1329
+
1330
+ /**
1331
+ * @expermental
1332
+ */
1333
+ export type AuthMFAAdminDeleteFactorResponse = RequestResult<{
1334
+ /** ID of the factor that was successfully deleted. */
1335
+ id: string
1336
+ }>
1337
+ /**
1338
+ * @expermental
1339
+ */
1340
+ export type AuthMFAAdminDeleteFactorParams = {
1341
+ /** ID of the MFA factor to delete. */
1342
+ id: string
1343
+
1344
+ /** ID of the user whose factor is being deleted. */
1345
+ userId: string
1346
+ }
1347
+
1348
+ /**
1349
+ * @expermental
1350
+ */
1351
+ export type AuthMFAAdminListFactorsResponse = RequestResult<{
1352
+ /** All factors attached to the user. */
1353
+ factors: Factor[]
1354
+ }>
1355
+
1356
+ /**
1357
+ * @expermental
1358
+ */
1359
+ export type AuthMFAAdminListFactorsParams = {
1360
+ /** ID of the user. */
1361
+ userId: string
1362
+ }
1363
+
1364
+ /**
1365
+ * Contains the full multi-factor authentication administration API.
1366
+ *
1367
+ * @expermental
1368
+ */
1369
+ export interface GoTrueAdminMFAApi {
1370
+ /**
1371
+ * Lists all factors associated to a user.
1372
+ *
1373
+ */
1374
+ listFactors(params: AuthMFAAdminListFactorsParams): Promise<AuthMFAAdminListFactorsResponse>
1375
+
1376
+ /**
1377
+ * Deletes a factor on a user. This will log the user out of all active
1378
+ * sessions if the deleted factor was verified.
1379
+ *
1380
+ * @see {@link GoTrueMFAApi#unenroll}
1381
+ *
1382
+ * @expermental
1383
+ */
1384
+ deleteFactor(params: AuthMFAAdminDeleteFactorParams): Promise<AuthMFAAdminDeleteFactorResponse>
1385
+ }
1386
+
1387
+ type AnyFunction = (...args: any[]) => any
1388
+ type MaybePromisify<T> = T | Promise<T>
1389
+
1390
+ type PromisifyMethods<T> = {
1391
+ [K in keyof T]: T[K] extends AnyFunction
1392
+ ? (...args: Parameters<T[K]>) => MaybePromisify<ReturnType<T[K]>>
1393
+ : T[K]
1394
+ }
1395
+
1396
+ export type SupportedStorage = PromisifyMethods<
1397
+ Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>
1398
+ > & {
1399
+ /**
1400
+ * If set to `true` signals to the library that the storage medium is used
1401
+ * on a server and the values may not be authentic, such as reading from
1402
+ * request cookies. Implementations should not set this to true if the client
1403
+ * is used on a server that reads storage information from authenticated
1404
+ * sources, such as a secure database or file.
1405
+ */
1406
+ isServer?: boolean
1407
+ }
1408
+
1409
+ export type InitializeResult = { error: AuthError | null }
1410
+
1411
+ export type CallRefreshTokenResult = RequestResult<Session>
1412
+
1413
+ export type Pagination = {
1414
+ [key: string]: any
1415
+ nextPage: number | null
1416
+ lastPage: number
1417
+ total: number
1418
+ }
1419
+
1420
+ export type PageParams = {
1421
+ /** The page number */
1422
+ page?: number
1423
+ /** Number of items returned per page */
1424
+ perPage?: number
1425
+ }
1426
+
1427
+ export type SignOut = {
1428
+ /**
1429
+ * Determines which sessions should be
1430
+ * logged out. Global means all
1431
+ * sessions by this account. Local
1432
+ * means only this session. Others
1433
+ * means all other sessions except the
1434
+ * current one. When using others,
1435
+ * there is no sign-out event fired on
1436
+ * the current session!
1437
+ */
1438
+ scope?: 'global' | 'local' | 'others'
1439
+ }
1440
+
1441
+ type MFAEnrollParamsBase<T extends FactorType> = {
1442
+ /** The type of factor being enrolled. */
1443
+ factorType: T
1444
+ /** Human readable name assigned to the factor. */
1445
+ friendlyName?: string
1446
+ }
1447
+
1448
+ type MFAEnrollTOTPParamFields = {
1449
+ /** Domain which the user is enrolled with. */
1450
+ issuer?: string
1451
+ }
1452
+
1453
+ export type MFAEnrollTOTPParams = Prettify<MFAEnrollParamsBase<'totp'> & MFAEnrollTOTPParamFields>
1454
+
1455
+ type MFAEnrollPhoneParamFields = {
1456
+ /** Phone number associated with a factor. Number should conform to E.164 format */
1457
+ phone: string
1458
+ }
1459
+ export type MFAEnrollPhoneParams = Prettify<
1460
+ MFAEnrollParamsBase<'phone'> & MFAEnrollPhoneParamFields
1461
+ >
1462
+
1463
+ type MFAEnrollWebauthnFields = {
1464
+ /** no extra fields for now, kept for consistency and for possible future changes */
1465
+ }
1466
+
1467
+ /**
1468
+ * Parameters for enrolling a WebAuthn factor.
1469
+ * Creates an unverified WebAuthn factor that must be verified with a credential.
1470
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1471
+ */
1472
+ export type MFAEnrollWebauthnParams = Prettify<
1473
+ MFAEnrollParamsBase<'webauthn'> & MFAEnrollWebauthnFields
1474
+ >
1475
+
1476
+ type AuthMFAEnrollResponseBase<T extends FactorType> = {
1477
+ /** ID of the factor that was just enrolled (in an unverified state). */
1478
+ id: string
1479
+
1480
+ /** Type of MFA factor.*/
1481
+ type: T
1482
+
1483
+ /** Friendly name of the factor, useful for distinguishing between factors **/
1484
+ friendly_name?: string
1485
+ }
1486
+
1487
+ type AuthMFAEnrollTOTPResponseFields = {
1488
+ /** TOTP enrollment information. */
1489
+ totp: {
1490
+ /** Contains a QR code encoding the authenticator URI. You can
1491
+ * convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
1492
+ * the value. Avoid logging this value to the console. */
1493
+ qr_code: string
1494
+
1495
+ /** The TOTP secret (also encoded in the QR code). Show this secret
1496
+ * in a password-style field to the user, in case they are unable to
1497
+ * scan the QR code. Avoid logging this value to the console. */
1498
+ secret: string
1499
+
1500
+ /** The authenticator URI encoded within the QR code, should you need
1501
+ * to use it. Avoid loggin this value to the console. */
1502
+ uri: string
1503
+ }
1504
+ }
1505
+
1506
+ export type AuthMFAEnrollTOTPResponse = RequestResult<
1507
+ Prettify<AuthMFAEnrollResponseBase<'totp'> & AuthMFAEnrollTOTPResponseFields>
1508
+ >
1509
+
1510
+ type AuthMFAEnrollPhoneResponseFields = {
1511
+ /** Phone number of the MFA factor in E.164 format. Used to send messages */
1512
+ phone: string
1513
+ }
1514
+
1515
+ export type AuthMFAEnrollPhoneResponse = RequestResult<
1516
+ Prettify<AuthMFAEnrollResponseBase<'phone'> & AuthMFAEnrollPhoneResponseFields>
1517
+ >
1518
+
1519
+ type AuthMFAEnrollWebauthnFields = {
1520
+ /** no extra fields for now, kept for consistency and for possible future changes */
1521
+ }
1522
+
1523
+ /**
1524
+ * Response type for WebAuthn factor enrollment.
1525
+ * Returns the enrolled factor ID and metadata.
1526
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1527
+ */
1528
+ export type AuthMFAEnrollWebauthnResponse = RequestResult<
1529
+ Prettify<AuthMFAEnrollResponseBase<'webauthn'> & AuthMFAEnrollWebauthnFields>
1530
+ >
1531
+
1532
+ export type JwtHeader = {
1533
+ alg: 'RS256' | 'ES256' | 'HS256'
1534
+ kid: string
1535
+ typ: string
1536
+ }
1537
+
1538
+ export type RequiredClaims = {
1539
+ iss: string
1540
+ sub: string
1541
+ aud: string | string[]
1542
+ exp: number
1543
+ iat: number
1544
+ role: string
1545
+ aal: AuthenticatorAssuranceLevels
1546
+ session_id: string
1547
+ }
1548
+
1549
+ /**
1550
+ * JWT Payload containing claims for Supabase authentication tokens.
1551
+ *
1552
+ * Required claims (iss, aud, exp, iat, sub, role, aal, session_id) are inherited from RequiredClaims.
1553
+ * All other claims are optional as they can be customized via Custom Access Token Hooks.
1554
+ *
1555
+ * @see https://supabase.com/docs/guides/auth/jwt-fields
1556
+ */
1557
+ export interface JwtPayload extends RequiredClaims {
1558
+ // Standard optional claims (can be customized via custom access token hooks)
1559
+ email?: string
1560
+ phone?: string
1561
+ is_anonymous?: boolean
1562
+
1563
+ // Optional claims
1564
+ jti?: string
1565
+ nbf?: number
1566
+ app_metadata?: UserAppMetadata
1567
+ user_metadata?: UserMetadata
1568
+ /**
1569
+ * Authentication Method References.
1570
+ * Supports both RFC-8176 compliant format (string[]) and detailed format (AMREntry[]).
1571
+ * - String format: ['password', 'otp'] - RFC-8176 compliant
1572
+ * - Object format: [{ method: 'password', timestamp: 1234567890 }] - includes timestamps
1573
+ */
1574
+ amr?: AMREntry[] | string[]
1575
+
1576
+ // Special claims (only in anon/service role tokens)
1577
+ ref?: string
1578
+
1579
+ // Allow custom claims via custom access token hooks
1580
+ [key: string]: any
1581
+ }
1582
+
1583
+ export interface JWK {
1584
+ kty: 'RSA' | 'EC' | 'oct'
1585
+ key_ops: string[]
1586
+ alg?: string
1587
+ kid?: string
1588
+ [key: string]: any
1589
+ }
1590
+
1591
+ export const SIGN_OUT_SCOPES = ['global', 'local', 'others'] as const
1592
+ export type SignOutScope = (typeof SIGN_OUT_SCOPES)[number]
1593
+
1594
+ /**
1595
+ * OAuth client grant types supported by the OAuth 2.1 server.
1596
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1597
+ */
1598
+ export type OAuthClientGrantType = 'authorization_code' | 'refresh_token'
1599
+
1600
+ /**
1601
+ * OAuth client response types supported by the OAuth 2.1 server.
1602
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1603
+ */
1604
+ export type OAuthClientResponseType = 'code'
1605
+
1606
+ /**
1607
+ * OAuth client type indicating whether the client can keep credentials confidential.
1608
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1609
+ */
1610
+ export type OAuthClientType = 'public' | 'confidential'
1611
+
1612
+ /**
1613
+ * OAuth client registration type.
1614
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1615
+ */
1616
+ export type OAuthClientRegistrationType = 'dynamic' | 'manual'
1617
+
1618
+ /**
1619
+ * OAuth client token endpoint authentication method.
1620
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1621
+ */
1622
+ export type OAuthClientTokenEndpointAuthMethod =
1623
+ | 'none'
1624
+ | 'client_secret_basic'
1625
+ | 'client_secret_post'
1626
+
1627
+ /**
1628
+ * OAuth client object returned from the OAuth 2.1 server.
1629
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1630
+ */
1631
+ export type OAuthClient = {
1632
+ /** Unique identifier for the OAuth client */
1633
+ client_id: string
1634
+ /** Human-readable name of the OAuth client */
1635
+ client_name: string
1636
+ /** Client secret (only returned on registration and regeneration) */
1637
+ client_secret?: string
1638
+ /** Type of OAuth client */
1639
+ client_type: OAuthClientType
1640
+ /** Token endpoint authentication method */
1641
+ token_endpoint_auth_method: OAuthClientTokenEndpointAuthMethod
1642
+ /** Registration type of the client */
1643
+ registration_type: OAuthClientRegistrationType
1644
+ /** URI of the OAuth client */
1645
+ client_uri?: string
1646
+ /** URI of the OAuth client's logo */
1647
+ logo_uri?: string
1648
+ /** Array of allowed redirect URIs */
1649
+ redirect_uris: string[]
1650
+ /** Array of allowed grant types */
1651
+ grant_types: OAuthClientGrantType[]
1652
+ /** Array of allowed response types */
1653
+ response_types: OAuthClientResponseType[]
1654
+ /** Scope of the OAuth client */
1655
+ scope?: string
1656
+ /** Timestamp when the client was created */
1657
+ created_at: string
1658
+ /** Timestamp when the client was last updated */
1659
+ updated_at: string
1660
+ }
1661
+
1662
+ /**
1663
+ * Parameters for creating a new OAuth client.
1664
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1665
+ */
1666
+ export type CreateOAuthClientParams = {
1667
+ /** Human-readable name of the OAuth client */
1668
+ client_name: string
1669
+ /** URI of the OAuth client */
1670
+ client_uri?: string
1671
+ /** Array of allowed redirect URIs */
1672
+ redirect_uris: string[]
1673
+ /** Array of allowed grant types (optional, defaults to authorization_code and refresh_token) */
1674
+ grant_types?: OAuthClientGrantType[]
1675
+ /** Array of allowed response types (optional, defaults to code) */
1676
+ response_types?: OAuthClientResponseType[]
1677
+ /** Scope of the OAuth client */
1678
+ scope?: string
1679
+ /** Token endpoint authentication method (defaults to server default if not specified) */
1680
+ token_endpoint_auth_method?: OAuthClientTokenEndpointAuthMethod
1681
+ }
1682
+
1683
+ /**
1684
+ * Parameters for updating an existing OAuth client.
1685
+ * All fields are optional. Only provided fields will be updated.
1686
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1687
+ */
1688
+ export type UpdateOAuthClientParams = {
1689
+ /** Human-readable name of the OAuth client */
1690
+ client_name?: string
1691
+ /** URI of the OAuth client */
1692
+ client_uri?: string
1693
+ /** URI of the OAuth client's logo */
1694
+ logo_uri?: string
1695
+ /** Array of allowed redirect URIs */
1696
+ redirect_uris?: string[]
1697
+ /** Array of allowed grant types */
1698
+ grant_types?: OAuthClientGrantType[]
1699
+ /** Token endpoint authentication method */
1700
+ token_endpoint_auth_method?: OAuthClientTokenEndpointAuthMethod
1701
+ }
1702
+
1703
+ /**
1704
+ * Response type for OAuth client operations.
1705
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1706
+ */
1707
+ export type OAuthClientResponse = RequestResult<OAuthClient>
1708
+
1709
+ /**
1710
+ * Response type for listing OAuth clients.
1711
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1712
+ */
1713
+ export type OAuthClientListResponse =
1714
+ | {
1715
+ data: { clients: OAuthClient[]; aud: string } & Pagination
1716
+ error: null
1717
+ }
1718
+ | {
1719
+ data: { clients: [] }
1720
+ error: AuthError
1721
+ }
1722
+
1723
+ /**
1724
+ * Contains all OAuth client administration methods.
1725
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1726
+ */
1727
+ export interface GoTrueAdminOAuthApi {
1728
+ /**
1729
+ * Lists all OAuth clients with optional pagination.
1730
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1731
+ *
1732
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1733
+ */
1734
+ listClients(params?: PageParams): Promise<OAuthClientListResponse>
1735
+
1736
+ /**
1737
+ * Creates a new OAuth client.
1738
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1739
+ *
1740
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1741
+ */
1742
+ createClient(params: CreateOAuthClientParams): Promise<OAuthClientResponse>
1743
+
1744
+ /**
1745
+ * Gets details of a specific OAuth client.
1746
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1747
+ *
1748
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1749
+ */
1750
+ getClient(clientId: string): Promise<OAuthClientResponse>
1751
+
1752
+ /**
1753
+ * Updates an existing OAuth client.
1754
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1755
+ *
1756
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1757
+ */
1758
+ updateClient(clientId: string, params: UpdateOAuthClientParams): Promise<OAuthClientResponse>
1759
+
1760
+ /**
1761
+ * Deletes an OAuth client.
1762
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1763
+ *
1764
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1765
+ */
1766
+ deleteClient(clientId: string): Promise<{ data: null; error: AuthError | null }>
1767
+
1768
+ /**
1769
+ * Regenerates the secret for an OAuth client.
1770
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1771
+ *
1772
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1773
+ */
1774
+ regenerateClientSecret(clientId: string): Promise<OAuthClientResponse>
1775
+ }
1776
+
1777
+ /**
1778
+ * Type of custom identity provider.
1779
+ */
1780
+ export type CustomProviderType = 'oauth2' | 'oidc'
1781
+
1782
+ /**
1783
+ * OIDC discovery document fields.
1784
+ * Populated when the server successfully fetches and validates the
1785
+ * provider's OpenID Connect discovery document.
1786
+ */
1787
+ export type OIDCDiscoveryDocument = {
1788
+ /** The issuer identifier */
1789
+ issuer: string
1790
+ /** URL of the authorization endpoint */
1791
+ authorization_endpoint: string
1792
+ /** URL of the token endpoint */
1793
+ token_endpoint: string
1794
+ /** URL of the JSON Web Key Set */
1795
+ jwks_uri: string
1796
+ /** URL of the userinfo endpoint */
1797
+ userinfo_endpoint?: string
1798
+ /** URL of the revocation endpoint */
1799
+ revocation_endpoint?: string
1800
+ /** List of supported scopes */
1801
+ supported_scopes?: string[]
1802
+ /** List of supported response types */
1803
+ supported_response_types?: string[]
1804
+ /** List of supported subject types */
1805
+ supported_subject_types?: string[]
1806
+ /** List of supported ID token signing algorithms */
1807
+ supported_id_token_signing_algs?: string[]
1808
+ }
1809
+
1810
+ /**
1811
+ * Custom OAuth/OIDC provider object returned from the admin API.
1812
+ */
1813
+ export type CustomOAuthProvider = {
1814
+ /** Unique identifier (UUID) */
1815
+ id: string
1816
+ /** Provider type */
1817
+ provider_type: CustomProviderType
1818
+ /** Provider identifier (e.g. `custom:mycompany`) */
1819
+ identifier: string
1820
+ /** Human-readable name */
1821
+ name: string
1822
+ /** OAuth client ID */
1823
+ client_id: string
1824
+ /** Additional client IDs accepted during token validation */
1825
+ acceptable_client_ids?: string[]
1826
+ /** OAuth scopes requested during authorization */
1827
+ scopes?: string[]
1828
+ /** Whether PKCE is enabled */
1829
+ pkce_enabled?: boolean
1830
+ /** Mapping of provider attributes to Supabase user attributes */
1831
+ attribute_mapping?: Record<string, any>
1832
+ /** Additional parameters sent with the authorization request */
1833
+ authorization_params?: Record<string, string>
1834
+ /** Whether the provider is enabled */
1835
+ enabled?: boolean
1836
+ /** Whether email is optional for this provider */
1837
+ email_optional?: boolean
1838
+ /** OIDC issuer URL */
1839
+ issuer?: string
1840
+ /** OIDC discovery URL */
1841
+ discovery_url?: string
1842
+ /** Whether to skip nonce check (OIDC) */
1843
+ skip_nonce_check?: boolean
1844
+ /** OAuth2 authorization URL */
1845
+ authorization_url?: string
1846
+ /** OAuth2 token URL */
1847
+ token_url?: string
1848
+ /** OAuth2 userinfo URL */
1849
+ userinfo_url?: string
1850
+ /** JWKS URI for token verification */
1851
+ jwks_uri?: string
1852
+ /** OIDC discovery document (OIDC providers only) */
1853
+ discovery_document?: OIDCDiscoveryDocument | null
1854
+ /** Timestamp when the provider was created */
1855
+ created_at: string
1856
+ /** Timestamp when the provider was last updated */
1857
+ updated_at: string
1858
+ }
1859
+
1860
+ /**
1861
+ * Parameters for creating a new custom provider.
1862
+ */
1863
+ export type CreateCustomProviderParams = {
1864
+ /** Provider type */
1865
+ provider_type: CustomProviderType
1866
+ /** Provider identifier (e.g. `custom:mycompany`) */
1867
+ identifier: string
1868
+ /** Human-readable name */
1869
+ name: string
1870
+ /** OAuth client ID */
1871
+ client_id: string
1872
+ /** OAuth client secret (write-only, not returned in responses) */
1873
+ client_secret: string
1874
+ /** Additional client IDs accepted during token validation */
1875
+ acceptable_client_ids?: string[]
1876
+ /** OAuth scopes requested during authorization */
1877
+ scopes?: string[]
1878
+ /** Whether PKCE is enabled */
1879
+ pkce_enabled?: boolean
1880
+ /** Mapping of provider attributes to Supabase user attributes */
1881
+ attribute_mapping?: Record<string, any>
1882
+ /** Additional parameters sent with the authorization request */
1883
+ authorization_params?: Record<string, string>
1884
+ /** Whether the provider is enabled */
1885
+ enabled?: boolean
1886
+ /** Whether email is optional for this provider */
1887
+ email_optional?: boolean
1888
+ /** OIDC issuer URL */
1889
+ issuer?: string
1890
+ /** OIDC discovery URL */
1891
+ discovery_url?: string
1892
+ /** Whether to skip nonce check (OIDC) */
1893
+ skip_nonce_check?: boolean
1894
+ /** OAuth2 authorization URL */
1895
+ authorization_url?: string
1896
+ /** OAuth2 token URL */
1897
+ token_url?: string
1898
+ /** OAuth2 userinfo URL */
1899
+ userinfo_url?: string
1900
+ /** JWKS URI for token verification */
1901
+ jwks_uri?: string
1902
+ }
1903
+
1904
+ /**
1905
+ * Parameters for updating an existing custom provider.
1906
+ * All fields are optional. Only provided fields will be updated.
1907
+ * `provider_type` and `identifier` are immutable and cannot be changed.
1908
+ */
1909
+ export type UpdateCustomProviderParams = {
1910
+ /** Human-readable name */
1911
+ name?: string
1912
+ /** OAuth client ID */
1913
+ client_id?: string
1914
+ /** OAuth client secret (write-only, not returned in responses) */
1915
+ client_secret?: string
1916
+ /** Additional client IDs accepted during token validation */
1917
+ acceptable_client_ids?: string[]
1918
+ /** OAuth scopes requested during authorization */
1919
+ scopes?: string[]
1920
+ /** Whether PKCE is enabled */
1921
+ pkce_enabled?: boolean
1922
+ /** Mapping of provider attributes to Supabase user attributes */
1923
+ attribute_mapping?: Record<string, any>
1924
+ /** Additional parameters sent with the authorization request */
1925
+ authorization_params?: Record<string, string>
1926
+ /** Whether the provider is enabled */
1927
+ enabled?: boolean
1928
+ /** Whether email is optional for this provider */
1929
+ email_optional?: boolean
1930
+ /** OIDC issuer URL */
1931
+ issuer?: string
1932
+ /** OIDC discovery URL */
1933
+ discovery_url?: string
1934
+ /** Whether to skip nonce check (OIDC) */
1935
+ skip_nonce_check?: boolean
1936
+ /** OAuth2 authorization URL */
1937
+ authorization_url?: string
1938
+ /** OAuth2 token URL */
1939
+ token_url?: string
1940
+ /** OAuth2 userinfo URL */
1941
+ userinfo_url?: string
1942
+ /** JWKS URI for token verification */
1943
+ jwks_uri?: string
1944
+ }
1945
+
1946
+ /**
1947
+ * Parameters for listing custom providers.
1948
+ */
1949
+ export type ListCustomProvidersParams = {
1950
+ /** Filter by provider type */
1951
+ type?: CustomProviderType
1952
+ }
1953
+
1954
+ /**
1955
+ * Response type for custom provider operations.
1956
+ */
1957
+ export type CustomProviderResponse = RequestResult<CustomOAuthProvider>
1958
+
1959
+ /**
1960
+ * Response type for listing custom providers.
1961
+ */
1962
+ export type CustomProviderListResponse =
1963
+ | {
1964
+ data: { providers: CustomOAuthProvider[] }
1965
+ error: null
1966
+ }
1967
+ | {
1968
+ data: { providers: [] }
1969
+ error: AuthError
1970
+ }
1971
+
1972
+ /**
1973
+ * Contains all custom OIDC/OAuth provider administration methods.
1974
+ */
1975
+ export interface GoTrueAdminCustomProvidersApi {
1976
+ /**
1977
+ * Lists all custom providers with optional type filter.
1978
+ *
1979
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1980
+ */
1981
+ listProviders(params?: ListCustomProvidersParams): Promise<CustomProviderListResponse>
1982
+
1983
+ /**
1984
+ * Creates a new custom OIDC/OAuth provider.
1985
+ *
1986
+ * For OIDC providers, the server fetches and validates the OpenID Connect discovery document
1987
+ * from the issuer's well-known endpoint (or the provided `discovery_url`) at creation time.
1988
+ * This may return a validation error (`error_code: "validation_failed"`) if the discovery
1989
+ * document is unreachable, not valid JSON, missing required fields, or if the issuer
1990
+ * in the document does not match the expected issuer.
1991
+ *
1992
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1993
+ */
1994
+ createProvider(params: CreateCustomProviderParams): Promise<CustomProviderResponse>
1995
+
1996
+ /**
1997
+ * Gets details of a specific custom provider by identifier.
1998
+ *
1999
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
2000
+ */
2001
+ getProvider(identifier: string): Promise<CustomProviderResponse>
2002
+
2003
+ /**
2004
+ * Updates an existing custom provider.
2005
+ *
2006
+ * When `issuer` or `discovery_url` is changed on an OIDC provider, the server re-fetches and
2007
+ * validates the discovery document before persisting. This may return a validation error
2008
+ * (`error_code: "validation_failed"`) if the discovery document is unreachable, invalid, or
2009
+ * the issuer does not match.
2010
+ *
2011
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
2012
+ */
2013
+ updateProvider(
2014
+ identifier: string,
2015
+ params: UpdateCustomProviderParams
2016
+ ): Promise<CustomProviderResponse>
2017
+
2018
+ /**
2019
+ * Deletes a custom provider.
2020
+ *
2021
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
2022
+ */
2023
+ deleteProvider(identifier: string): Promise<{ data: null; error: AuthError | null }>
2024
+ }
2025
+
2026
+ /**
2027
+ * OAuth client details in an authorization request.
2028
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2029
+ */
2030
+ export type OAuthAuthorizationClient = {
2031
+ /** Unique identifier for the OAuth client (UUID) */
2032
+ id: string
2033
+ /** Human-readable name of the OAuth client */
2034
+ name: string
2035
+ /** URI of the OAuth client's website */
2036
+ uri: string
2037
+ /** URI of the OAuth client's logo */
2038
+ logo_uri: string
2039
+ }
2040
+
2041
+ /**
2042
+ * OAuth authorization details when user needs to provide consent.
2043
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2044
+ *
2045
+ * This response includes all information needed to display a consent page:
2046
+ * client details, user info, requested scopes, and where the user will be redirected.
2047
+ *
2048
+ * Note: `redirect_uri` is the base URI (e.g., "https://app.com/callback") without
2049
+ * query parameters. After consent, you'll receive a complete `redirect_url` with
2050
+ * the authorization code and state parameters appended.
2051
+ */
2052
+ export type OAuthAuthorizationDetails = {
2053
+ /** The authorization ID used to approve or deny the request */
2054
+ authorization_id: string
2055
+ /** The OAuth client's registered redirect URI (base URI without query parameters) */
2056
+ redirect_uri: string
2057
+ /** OAuth client requesting authorization */
2058
+ client: OAuthAuthorizationClient
2059
+ /** User object associated with the authorization */
2060
+ user: {
2061
+ /** User ID (UUID) */
2062
+ id: string
2063
+ /** User email */
2064
+ email: string
2065
+ }
2066
+ /** Space-separated list of requested scopes (e.g., "openid profile email") */
2067
+ scope: string
2068
+ }
2069
+
2070
+ /**
2071
+ * OAuth redirect response when user has already consented or after consent decision.
2072
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2073
+ *
2074
+ * This response is returned in three scenarios:
2075
+ * 1. User already consented to these scopes (auto-approved)
2076
+ * 2. User just approved the authorization request
2077
+ * 3. User just denied the authorization request
2078
+ *
2079
+ * The `redirect_url` is a complete URL ready for redirecting the user back to the
2080
+ * OAuth client, including authorization code (on success) or error (on denial) in
2081
+ * query parameters, along with the state parameter if one was provided.
2082
+ */
2083
+ export type OAuthRedirect = {
2084
+ /** Complete redirect URL with authorization code and state parameters (e.g., "https://app.com/callback?code=xxx&state=yyy") */
2085
+ redirect_url: string
2086
+ }
2087
+
2088
+ /**
2089
+ * Response type for getting OAuth authorization details.
2090
+ * Returns either full authorization details (if consent needed) or redirect URL (if already consented).
2091
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2092
+ *
2093
+ * @example
2094
+ * ```typescript
2095
+ * const { data, error } = await supabase.auth.oauth.getAuthorizationDetails(authorizationId)
2096
+ *
2097
+ * if (error) {
2098
+ * console.error('Error:', error)
2099
+ * } else if ('authorization_id' in data) {
2100
+ * // User needs to provide consent - show consent page
2101
+ * console.log('Client:', data.client.name)
2102
+ * console.log('Scopes:', data.scope)
2103
+ * console.log('Redirect URI:', data.redirect_uri)
2104
+ * } else {
2105
+ * // User already consented - redirect immediately
2106
+ * window.location.href = data.redirect_url
2107
+ * }
2108
+ * ```
2109
+ */
2110
+ export type AuthOAuthAuthorizationDetailsResponse = RequestResult<
2111
+ OAuthAuthorizationDetails | OAuthRedirect
2112
+ >
2113
+
2114
+ /**
2115
+ * Response type for OAuth consent decision (approve/deny).
2116
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2117
+ */
2118
+ export type AuthOAuthConsentResponse = RequestResult<OAuthRedirect>
2119
+
2120
+ /**
2121
+ * An OAuth grant representing a user's authorization of an OAuth client.
2122
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2123
+ */
2124
+ export type OAuthGrant = {
2125
+ /** OAuth client information */
2126
+ client: OAuthAuthorizationClient
2127
+ /** Array of scopes granted to this client */
2128
+ scopes: string[]
2129
+ /** Timestamp when the grant was created (ISO 8601 date-time) */
2130
+ granted_at: string
2131
+ }
2132
+
2133
+ /**
2134
+ * Response type for listing user's OAuth grants.
2135
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2136
+ */
2137
+ export type AuthOAuthGrantsResponse = RequestResult<OAuthGrant[]>
2138
+
2139
+ /**
2140
+ * Response type for revoking an OAuth grant.
2141
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2142
+ */
2143
+ export type AuthOAuthRevokeGrantResponse = RequestResult<{}>
2144
+
2145
+ /**
2146
+ * Contains all OAuth 2.1 authorization server user-facing methods.
2147
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2148
+ *
2149
+ * These methods are used to implement the consent page.
2150
+ */
2151
+ export interface AuthOAuthServerApi {
2152
+ /**
2153
+ * Retrieves details about an OAuth authorization request.
2154
+ * Used to display consent information to the user.
2155
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2156
+ *
2157
+ * This method returns one of two response types:
2158
+ * - `OAuthAuthorizationDetails`: User needs to consent - show consent page with client info
2159
+ * - `OAuthRedirect`: User already consented - redirect immediately to the OAuth client
2160
+ *
2161
+ * Use type narrowing to distinguish between the responses:
2162
+ * ```typescript
2163
+ * if ('authorization_id' in data) {
2164
+ * // Show consent page
2165
+ * } else {
2166
+ * // Redirect to data.redirect_url
2167
+ * }
2168
+ * ```
2169
+ *
2170
+ * @param authorizationId - The authorization ID from the authorization request
2171
+ * @returns Authorization details or redirect URL depending on consent status
2172
+ */
2173
+ getAuthorizationDetails(authorizationId: string): Promise<AuthOAuthAuthorizationDetailsResponse>
2174
+
2175
+ /**
2176
+ * Approves an OAuth authorization request.
2177
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2178
+ *
2179
+ * After approval, the user's consent is stored and an authorization code is generated.
2180
+ * The response contains a complete redirect URL with the authorization code and state.
2181
+ *
2182
+ * @param authorizationId - The authorization ID to approve
2183
+ * @param options - Optional parameters
2184
+ * @param options.skipBrowserRedirect - If false (default), automatically redirects the browser to the OAuth client. If true, returns the redirect_url without automatic redirect (useful for custom handling).
2185
+ * @returns Redirect URL to send the user back to the OAuth client with authorization code
2186
+ */
2187
+ approveAuthorization(
2188
+ authorizationId: string,
2189
+ options?: { skipBrowserRedirect?: boolean }
2190
+ ): Promise<AuthOAuthConsentResponse>
2191
+
2192
+ /**
2193
+ * Denies an OAuth authorization request.
2194
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2195
+ *
2196
+ * After denial, the response contains a redirect URL with an OAuth error
2197
+ * (access_denied) to inform the OAuth client that the user rejected the request.
2198
+ *
2199
+ * @param authorizationId - The authorization ID to deny
2200
+ * @param options - Optional parameters
2201
+ * @param options.skipBrowserRedirect - If false (default), automatically redirects the browser to the OAuth client. If true, returns the redirect_url without automatic redirect (useful for custom handling).
2202
+ * @returns Redirect URL to send the user back to the OAuth client with error information
2203
+ */
2204
+ denyAuthorization(
2205
+ authorizationId: string,
2206
+ options?: { skipBrowserRedirect?: boolean }
2207
+ ): Promise<AuthOAuthConsentResponse>
2208
+
2209
+ /**
2210
+ * Lists all OAuth grants that the authenticated user has authorized.
2211
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2212
+ *
2213
+ * @returns Response with array of OAuth grants with client information and granted scopes
2214
+ */
2215
+ listGrants(): Promise<AuthOAuthGrantsResponse>
2216
+
2217
+ /**
2218
+ * Revokes a user's OAuth grant for a specific client.
2219
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2220
+ *
2221
+ * Revocation marks consent as revoked, deletes active sessions for that OAuth client,
2222
+ * and invalidates associated refresh tokens.
2223
+ *
2224
+ * @param options - Revocation options
2225
+ * @param options.clientId - The OAuth client identifier (UUID) to revoke access for
2226
+ * @returns Empty response on successful revocation
2227
+ */
2228
+ revokeGrant(options: { clientId: string }): Promise<AuthOAuthRevokeGrantResponse>
2229
+ }