@supabase/gotrue-js 2.72.0 → 2.73.0-rc.3
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.
- package/dist/main/GoTrueClient.d.ts +7 -1
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +72 -19
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/errors.d.ts +1 -1
- package/dist/main/lib/errors.d.ts.map +1 -1
- package/dist/main/lib/errors.js.map +1 -1
- package/dist/main/lib/types.d.ts +214 -320
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/types.js +17 -1
- package/dist/main/lib/types.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/GoTrueClient.d.ts +7 -1
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +72 -19
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/errors.d.ts +1 -1
- package/dist/module/lib/errors.d.ts.map +1 -1
- package/dist/module/lib/errors.js.map +1 -1
- package/dist/module/lib/types.d.ts +214 -320
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/types.js +16 -0
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/version.js.map +1 -1
- package/package.json +2 -1
- package/src/GoTrueClient.ts +93 -22
- package/src/lib/errors.ts +1 -1
- package/src/lib/types.ts +285 -352
- package/src/lib/version.ts +1 -1
package/src/lib/types.ts
CHANGED
|
@@ -99,93 +99,76 @@ export type GoTrueClientOptions = {
|
|
|
99
99
|
hasCustomAuthorizationHeader?: boolean
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
const WeakPasswordReasons = ['length', 'characters', 'pwned'] as const
|
|
103
|
+
|
|
104
|
+
export type WeakPasswordReasons = typeof WeakPasswordReasons[number]
|
|
103
105
|
export type WeakPassword = {
|
|
104
106
|
reasons: WeakPasswordReasons[]
|
|
105
107
|
message: string
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Resolve mapped types and show the derived keys and their types when hovering in
|
|
112
|
+
* VS Code, instead of just showing the names those mapped types are defined with.
|
|
113
|
+
*/
|
|
114
|
+
export type Prettify<T> = T extends Function ? T : { [K in keyof T]: T[K] }
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* a shared result type that encapsulates errors instead of throwing them, allows you to optionally specify the ErrorType
|
|
118
|
+
*/
|
|
119
|
+
export type RequestResult<T, ErrorType extends Error = AuthError> =
|
|
109
120
|
| {
|
|
110
|
-
data:
|
|
111
|
-
user: User | null
|
|
112
|
-
session: Session | null
|
|
113
|
-
}
|
|
121
|
+
data: T
|
|
114
122
|
error: null
|
|
115
123
|
}
|
|
116
124
|
| {
|
|
117
|
-
data:
|
|
118
|
-
|
|
119
|
-
session: null
|
|
120
|
-
}
|
|
121
|
-
error: AuthError
|
|
125
|
+
data: null
|
|
126
|
+
error: Error extends AuthError ? AuthError : ErrorType
|
|
122
127
|
}
|
|
123
128
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
error: null
|
|
132
|
-
}
|
|
129
|
+
/**
|
|
130
|
+
* similar to RequestResult except it allows you to destructure the possible shape of the success response
|
|
131
|
+
* {@see RequestResult}
|
|
132
|
+
*/
|
|
133
|
+
export type RequestResultSafeDestructure<T> =
|
|
134
|
+
| { data: T; error: null }
|
|
133
135
|
| {
|
|
134
|
-
data: {
|
|
135
|
-
user: null
|
|
136
|
-
session: null
|
|
137
|
-
}
|
|
136
|
+
data: T extends object ? { [K in keyof T]: null } : null
|
|
138
137
|
error: AuthError
|
|
139
138
|
}
|
|
140
139
|
|
|
140
|
+
export type AuthResponse = RequestResultSafeDestructure<{
|
|
141
|
+
user: User | null
|
|
142
|
+
session: Session | null
|
|
143
|
+
}>
|
|
144
|
+
|
|
145
|
+
export type AuthResponsePassword = RequestResultSafeDestructure<{
|
|
146
|
+
user: User | null
|
|
147
|
+
session: Session | null
|
|
148
|
+
weak_password?: WeakPassword | null
|
|
149
|
+
}>
|
|
150
|
+
|
|
141
151
|
/**
|
|
142
152
|
* AuthOtpResponse is returned when OTP is used.
|
|
143
153
|
*
|
|
144
154
|
* {@see AuthResponse}
|
|
145
155
|
*/
|
|
146
|
-
export type AuthOtpResponse =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
| {
|
|
152
|
-
data: { user: null; session: null; messageId?: string | null }
|
|
153
|
-
error: AuthError
|
|
154
|
-
}
|
|
156
|
+
export type AuthOtpResponse = RequestResultSafeDestructure<{
|
|
157
|
+
user: null
|
|
158
|
+
session: null
|
|
159
|
+
messageId?: string | null
|
|
160
|
+
}>
|
|
155
161
|
|
|
156
|
-
export type AuthTokenResponse =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
session: Session
|
|
161
|
-
}
|
|
162
|
-
error: null
|
|
163
|
-
}
|
|
164
|
-
| {
|
|
165
|
-
data: {
|
|
166
|
-
user: null
|
|
167
|
-
session: null
|
|
168
|
-
}
|
|
169
|
-
error: AuthError
|
|
170
|
-
}
|
|
162
|
+
export type AuthTokenResponse = RequestResultSafeDestructure<{
|
|
163
|
+
user: User
|
|
164
|
+
session: Session
|
|
165
|
+
}>
|
|
171
166
|
|
|
172
|
-
export type AuthTokenResponsePassword =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
weakPassword?: WeakPassword
|
|
178
|
-
}
|
|
179
|
-
error: null
|
|
180
|
-
}
|
|
181
|
-
| {
|
|
182
|
-
data: {
|
|
183
|
-
user: null
|
|
184
|
-
session: null
|
|
185
|
-
weakPassword?: null
|
|
186
|
-
}
|
|
187
|
-
error: AuthError
|
|
188
|
-
}
|
|
167
|
+
export type AuthTokenResponsePassword = RequestResultSafeDestructure<{
|
|
168
|
+
user: User
|
|
169
|
+
session: Session
|
|
170
|
+
weakPassword?: WeakPassword
|
|
171
|
+
}>
|
|
189
172
|
|
|
190
173
|
export type OAuthResponse =
|
|
191
174
|
| {
|
|
@@ -203,38 +186,20 @@ export type OAuthResponse =
|
|
|
203
186
|
error: AuthError
|
|
204
187
|
}
|
|
205
188
|
|
|
206
|
-
export type SSOResponse =
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
url: string
|
|
217
|
-
}
|
|
218
|
-
error: null
|
|
219
|
-
}
|
|
220
|
-
| {
|
|
221
|
-
data: null
|
|
222
|
-
error: AuthError
|
|
223
|
-
}
|
|
189
|
+
export type SSOResponse = RequestResult<{
|
|
190
|
+
/**
|
|
191
|
+
* URL to open in a browser which will complete the sign-in flow by
|
|
192
|
+
* taking the user to the identity provider's authentication flow.
|
|
193
|
+
*
|
|
194
|
+
* On browsers you can set the URL to `window.location.href` to take
|
|
195
|
+
* the user to the authentication flow.
|
|
196
|
+
*/
|
|
197
|
+
url: string
|
|
198
|
+
}>
|
|
224
199
|
|
|
225
|
-
export type UserResponse =
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
user: User
|
|
229
|
-
}
|
|
230
|
-
error: null
|
|
231
|
-
}
|
|
232
|
-
| {
|
|
233
|
-
data: {
|
|
234
|
-
user: null
|
|
235
|
-
}
|
|
236
|
-
error: AuthError
|
|
237
|
-
}
|
|
200
|
+
export type UserResponse = RequestResultSafeDestructure<{
|
|
201
|
+
user: User
|
|
202
|
+
}>
|
|
238
203
|
|
|
239
204
|
export interface Session {
|
|
240
205
|
/**
|
|
@@ -262,7 +227,7 @@ export interface Session {
|
|
|
262
227
|
* A timestamp of when the token will expire. Returned when a login is confirmed.
|
|
263
228
|
*/
|
|
264
229
|
expires_at?: number
|
|
265
|
-
token_type:
|
|
230
|
+
token_type: 'bearer'
|
|
266
231
|
|
|
267
232
|
/**
|
|
268
233
|
* When using a separate user storage, accessing properties of this object will throw an error.
|
|
@@ -270,6 +235,21 @@ export interface Session {
|
|
|
270
235
|
user: User
|
|
271
236
|
}
|
|
272
237
|
|
|
238
|
+
const AMRMethods = [
|
|
239
|
+
'password',
|
|
240
|
+
'otp',
|
|
241
|
+
'oauth',
|
|
242
|
+
'totp',
|
|
243
|
+
'mfa/totp',
|
|
244
|
+
'mfa/phone',
|
|
245
|
+
'anonymous',
|
|
246
|
+
'sso/saml',
|
|
247
|
+
'magiclink',
|
|
248
|
+
'web3',
|
|
249
|
+
] as const
|
|
250
|
+
|
|
251
|
+
export type AMRMethod = typeof AMRMethods[number] | (string & {})
|
|
252
|
+
|
|
273
253
|
/**
|
|
274
254
|
* An authentication methord reference (AMR) entry.
|
|
275
255
|
*
|
|
@@ -280,7 +260,7 @@ export interface Session {
|
|
|
280
260
|
*/
|
|
281
261
|
export interface AMREntry {
|
|
282
262
|
/** Authentication method name. */
|
|
283
|
-
method:
|
|
263
|
+
method: AMRMethod
|
|
284
264
|
|
|
285
265
|
/**
|
|
286
266
|
* Timestamp when the method was successfully used. Represents number of
|
|
@@ -302,6 +282,19 @@ export interface UserIdentity {
|
|
|
302
282
|
updated_at?: string
|
|
303
283
|
}
|
|
304
284
|
|
|
285
|
+
export const FactorTypes = ['totp', 'phone'] as const
|
|
286
|
+
/**
|
|
287
|
+
* Type of factor. `totp` and `phone` supported with this version
|
|
288
|
+
*/
|
|
289
|
+
export type FactorType = typeof FactorTypes[number]
|
|
290
|
+
|
|
291
|
+
const FactorVerificationStatuses = ['verified', 'unverified'] as const
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
|
|
295
|
+
*/
|
|
296
|
+
type FactorVerificationStatus = typeof FactorVerificationStatuses[number]
|
|
297
|
+
|
|
305
298
|
/**
|
|
306
299
|
* A MFA factor.
|
|
307
300
|
*
|
|
@@ -309,7 +302,10 @@ export interface UserIdentity {
|
|
|
309
302
|
* @see {@link GoTrueMFAApi#listFactors}
|
|
310
303
|
* @see {@link GoTrueMFAAdminApi#listFactors}
|
|
311
304
|
*/
|
|
312
|
-
export
|
|
305
|
+
export type Factor<
|
|
306
|
+
Type extends FactorType = FactorType,
|
|
307
|
+
Status extends FactorVerificationStatus = typeof FactorVerificationStatuses[number]
|
|
308
|
+
> = {
|
|
313
309
|
/** ID of the factor. */
|
|
314
310
|
id: string
|
|
315
311
|
|
|
@@ -319,10 +315,12 @@ export interface Factor {
|
|
|
319
315
|
/**
|
|
320
316
|
* Type of factor. `totp` and `phone` supported with this version
|
|
321
317
|
*/
|
|
322
|
-
factor_type:
|
|
318
|
+
factor_type: Type
|
|
323
319
|
|
|
324
|
-
/**
|
|
325
|
-
|
|
320
|
+
/**
|
|
321
|
+
* The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
|
|
322
|
+
*/
|
|
323
|
+
status: Status
|
|
326
324
|
|
|
327
325
|
created_at: string
|
|
328
326
|
updated_at: string
|
|
@@ -361,7 +359,7 @@ export interface User {
|
|
|
361
359
|
identities?: UserIdentity[]
|
|
362
360
|
is_anonymous?: boolean
|
|
363
361
|
is_sso_user?: boolean
|
|
364
|
-
factors?: Factor[]
|
|
362
|
+
factors?: Factor<FactorType>[]
|
|
365
363
|
deleted_at?: string
|
|
366
364
|
}
|
|
367
365
|
|
|
@@ -500,65 +498,26 @@ export type SignInAnonymouslyCredentials = {
|
|
|
500
498
|
}
|
|
501
499
|
}
|
|
502
500
|
|
|
503
|
-
export type SignUpWithPasswordCredentials =
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
/** The redirect url embedded in the email link */
|
|
511
|
-
emailRedirectTo?: string
|
|
512
|
-
/**
|
|
513
|
-
* A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
|
|
514
|
-
*
|
|
515
|
-
* The `data` should be a JSON object that includes user-specific info, such as their first and last name.
|
|
516
|
-
*/
|
|
517
|
-
data?: object
|
|
518
|
-
/** Verification token received when the user completes the captcha on the site. */
|
|
519
|
-
captchaToken?: string
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
| {
|
|
523
|
-
/** The user's phone number. */
|
|
524
|
-
phone: string
|
|
525
|
-
/** The user's password. */
|
|
526
|
-
password: string
|
|
527
|
-
options?: {
|
|
528
|
-
/**
|
|
529
|
-
* A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
|
|
530
|
-
*
|
|
531
|
-
* The `data` should be a JSON object that includes user-specific info, such as their first and last name.
|
|
532
|
-
*/
|
|
533
|
-
data?: object
|
|
534
|
-
/** Verification token received when the user completes the captcha on the site. Requires a configured WhatsApp sender on Twilio */
|
|
535
|
-
captchaToken?: string
|
|
536
|
-
/** Messaging channel to use (e.g. whatsapp or sms) */
|
|
537
|
-
channel?: 'sms' | 'whatsapp'
|
|
538
|
-
}
|
|
501
|
+
export type SignUpWithPasswordCredentials = Prettify<
|
|
502
|
+
PasswordCredentialsBase & {
|
|
503
|
+
options?: {
|
|
504
|
+
emailRedirectTo?: string // only for email
|
|
505
|
+
data?: object
|
|
506
|
+
captchaToken?: string
|
|
507
|
+
channel?: 'sms' | 'whatsapp' // only for phone
|
|
539
508
|
}
|
|
509
|
+
}
|
|
510
|
+
>
|
|
540
511
|
|
|
541
|
-
|
|
542
|
-
| {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
| {
|
|
553
|
-
/** The user's phone number. */
|
|
554
|
-
phone: string
|
|
555
|
-
/** The user's password. */
|
|
556
|
-
password: string
|
|
557
|
-
options?: {
|
|
558
|
-
/** Verification token received when the user completes the captcha on the site. */
|
|
559
|
-
captchaToken?: string
|
|
560
|
-
}
|
|
561
|
-
}
|
|
512
|
+
type PasswordCredentialsBase =
|
|
513
|
+
| { email: string; password: string }
|
|
514
|
+
| { phone: string; password: string }
|
|
515
|
+
|
|
516
|
+
export type SignInWithPasswordCredentials = PasswordCredentialsBase & {
|
|
517
|
+
options?: {
|
|
518
|
+
captchaToken?: string
|
|
519
|
+
}
|
|
520
|
+
}
|
|
562
521
|
|
|
563
522
|
export type SignInWithPasswordlessCredentials =
|
|
564
523
|
| {
|
|
@@ -859,21 +818,10 @@ export type GenerateLinkParams =
|
|
|
859
818
|
| GenerateRecoveryLinkParams
|
|
860
819
|
| GenerateEmailChangeLinkParams
|
|
861
820
|
|
|
862
|
-
export type GenerateLinkResponse =
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
user: User
|
|
867
|
-
}
|
|
868
|
-
error: null
|
|
869
|
-
}
|
|
870
|
-
| {
|
|
871
|
-
data: {
|
|
872
|
-
properties: null
|
|
873
|
-
user: null
|
|
874
|
-
}
|
|
875
|
-
error: AuthError
|
|
876
|
-
}
|
|
821
|
+
export type GenerateLinkResponse = RequestResultSafeDestructure<{
|
|
822
|
+
properties: GenerateLinkProperties
|
|
823
|
+
user: User
|
|
824
|
+
}>
|
|
877
825
|
|
|
878
826
|
/** The properties related to the email link generated */
|
|
879
827
|
export type GenerateLinkProperties = {
|
|
@@ -912,125 +860,134 @@ export type MFAUnenrollParams = {
|
|
|
912
860
|
factorId: string
|
|
913
861
|
}
|
|
914
862
|
|
|
915
|
-
|
|
863
|
+
type MFAVerifyParamsBase = {
|
|
916
864
|
/** ID of the factor being verified. Returned in enroll(). */
|
|
917
865
|
factorId: string
|
|
918
|
-
|
|
919
866
|
/** ID of the challenge being verified. Returned in challenge(). */
|
|
920
867
|
challengeId: string
|
|
868
|
+
}
|
|
921
869
|
|
|
870
|
+
type MFAVerifyTOTPParamFields = {
|
|
922
871
|
/** Verification code provided by the user. */
|
|
923
872
|
code: string
|
|
924
873
|
}
|
|
925
874
|
|
|
926
|
-
export type
|
|
875
|
+
export type MFAVerifyTOTPParams = Prettify<MFAVerifyParamsBase & MFAVerifyTOTPParamFields>
|
|
876
|
+
|
|
877
|
+
type MFAVerifyPhoneParamFields = MFAVerifyTOTPParamFields
|
|
878
|
+
|
|
879
|
+
export type MFAVerifyPhoneParams = Prettify<MFAVerifyParamsBase & MFAVerifyPhoneParamFields>
|
|
880
|
+
|
|
881
|
+
export type MFAVerifyParams = MFAVerifyTOTPParams | MFAVerifyPhoneParams
|
|
882
|
+
|
|
883
|
+
type MFAChallengeParamsBase = {
|
|
927
884
|
/** ID of the factor to be challenged. Returned in enroll(). */
|
|
928
885
|
factorId: string
|
|
929
|
-
/** Messaging channel to use (e.g. whatsapp or sms). Only relevant for phone factors */
|
|
930
|
-
channel?: 'sms' | 'whatsapp'
|
|
931
886
|
}
|
|
932
887
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
888
|
+
const MFATOTPChannels = ['sms', 'whatsapp'] as const
|
|
889
|
+
export type MFATOTPChannel = typeof MFATOTPChannels[number]
|
|
890
|
+
|
|
891
|
+
export type MFAChallengeTOTPParams = Prettify<MFAChallengeParamsBase>
|
|
892
|
+
|
|
893
|
+
type MFAChallengePhoneParamFields<Channel extends MFATOTPChannel = MFATOTPChannel> = {
|
|
894
|
+
/** Messaging channel to use (e.g. whatsapp or sms). Only relevant for phone factors */
|
|
895
|
+
channel: Channel
|
|
938
896
|
}
|
|
939
897
|
|
|
940
|
-
export type
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
/** New access token (JWT) after successful verification. */
|
|
944
|
-
access_token: string
|
|
898
|
+
export type MFAChallengePhoneParams = Prettify<
|
|
899
|
+
MFAChallengeParamsBase & MFAChallengePhoneParamFields
|
|
900
|
+
>
|
|
945
901
|
|
|
946
|
-
|
|
947
|
-
token_type: string
|
|
902
|
+
export type MFAChallengeParams = MFAChallengeTOTPParams | MFAChallengePhoneParams
|
|
948
903
|
|
|
949
|
-
|
|
950
|
-
expires_in: number
|
|
904
|
+
type MFAChallengeAndVerifyParamsBase = Omit<MFAVerifyParamsBase, 'challengeId'>
|
|
951
905
|
|
|
952
|
-
|
|
953
|
-
refresh_token: string
|
|
906
|
+
type MFAChallengeAndVerifyTOTPParamFields = MFAVerifyTOTPParamFields
|
|
954
907
|
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
908
|
+
type MFAChallengeAndVerifyTOTPParams = Prettify<
|
|
909
|
+
MFAChallengeAndVerifyParamsBase & MFAChallengeAndVerifyTOTPParamFields
|
|
910
|
+
>
|
|
911
|
+
|
|
912
|
+
type MFAChallengeAndVerifyPhoneParamFields = MFAVerifyPhoneParamFields
|
|
913
|
+
|
|
914
|
+
type MFAChallengeAndVerifyPhoneParams = Prettify<
|
|
915
|
+
MFAChallengeAndVerifyParamsBase & MFAChallengeAndVerifyPhoneParamFields
|
|
916
|
+
>
|
|
917
|
+
|
|
918
|
+
export type MFAChallengeAndVerifyParams =
|
|
919
|
+
| MFAChallengeAndVerifyTOTPParams
|
|
920
|
+
| MFAChallengeAndVerifyPhoneParams
|
|
921
|
+
|
|
922
|
+
export type AuthMFAVerifyResponse = RequestResult<{
|
|
923
|
+
/** New access token (JWT) after successful verification. */
|
|
924
|
+
access_token: string
|
|
925
|
+
|
|
926
|
+
/** Type of token, always `bearer`. */
|
|
927
|
+
token_type: 'bearer'
|
|
928
|
+
|
|
929
|
+
/** Number of seconds in which the access token will expire. */
|
|
930
|
+
expires_in: number
|
|
931
|
+
|
|
932
|
+
/** Refresh token you can use to obtain new access tokens when expired. */
|
|
933
|
+
refresh_token: string
|
|
934
|
+
|
|
935
|
+
/** Updated user profile. */
|
|
936
|
+
user: User
|
|
937
|
+
}>
|
|
964
938
|
|
|
965
939
|
export type AuthMFAEnrollResponse = AuthMFAEnrollTOTPResponse | AuthMFAEnrollPhoneResponse
|
|
966
940
|
|
|
967
|
-
export type AuthMFAUnenrollResponse =
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
id: string
|
|
972
|
-
}
|
|
973
|
-
error: null
|
|
974
|
-
}
|
|
975
|
-
| { data: null; error: AuthError }
|
|
941
|
+
export type AuthMFAUnenrollResponse = RequestResult<{
|
|
942
|
+
/** ID of the factor that was successfully unenrolled. */
|
|
943
|
+
id: string
|
|
944
|
+
}>
|
|
976
945
|
|
|
977
|
-
export type AuthMFAChallengeResponse =
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
/** ID of the newly created challenge. */
|
|
981
|
-
id: string
|
|
946
|
+
export type AuthMFAChallengeResponse<T extends FactorType> = RequestResult<{
|
|
947
|
+
/** ID of the newly created challenge. */
|
|
948
|
+
id: string
|
|
982
949
|
|
|
983
|
-
|
|
984
|
-
|
|
950
|
+
/** Factor Type which generated the challenge */
|
|
951
|
+
type: T
|
|
985
952
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
error: null
|
|
990
|
-
}
|
|
991
|
-
| { data: null; error: AuthError }
|
|
953
|
+
/** Timestamp in UNIX seconds when this challenge will no longer be usable. */
|
|
954
|
+
expires_at: number
|
|
955
|
+
}>
|
|
992
956
|
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
957
|
+
/** response of ListFactors, which should contain all the types of factors that are available, this ensures we always include all */
|
|
958
|
+
export type AuthMFAListFactorsResponse<T extends typeof FactorTypes = typeof FactorTypes> =
|
|
959
|
+
RequestResult<
|
|
960
|
+
{
|
|
961
|
+
/** All available factors (verified and unverified). */
|
|
962
|
+
all: Prettify<Factor>[]
|
|
998
963
|
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
phone: Factor[]
|
|
1003
|
-
}
|
|
1004
|
-
error: null
|
|
964
|
+
// Dynamically create a property for each factor type with only verified factors
|
|
965
|
+
} & {
|
|
966
|
+
[K in T[number]]: Prettify<Factor<K, 'verified'>>[]
|
|
1005
967
|
}
|
|
1006
|
-
|
|
968
|
+
>
|
|
1007
969
|
|
|
1008
970
|
export type AuthenticatorAssuranceLevels = 'aal1' | 'aal2'
|
|
1009
971
|
|
|
1010
|
-
export type AuthMFAGetAuthenticatorAssuranceLevelResponse =
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
/** Current AAL level of the session. */
|
|
1014
|
-
currentLevel: AuthenticatorAssuranceLevels | null
|
|
972
|
+
export type AuthMFAGetAuthenticatorAssuranceLevelResponse = RequestResult<{
|
|
973
|
+
/** Current AAL level of the session. */
|
|
974
|
+
currentLevel: AuthenticatorAssuranceLevels | null
|
|
1015
975
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
976
|
+
/**
|
|
977
|
+
* Next possible AAL level for the session. If the next level is higher
|
|
978
|
+
* than the current one, the user should go through MFA.
|
|
979
|
+
*
|
|
980
|
+
* @see {@link GoTrueMFAApi#challenge}
|
|
981
|
+
*/
|
|
982
|
+
nextLevel: AuthenticatorAssuranceLevels | null
|
|
1023
983
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
error: null
|
|
1032
|
-
}
|
|
1033
|
-
| { data: null; error: AuthError }
|
|
984
|
+
/**
|
|
985
|
+
* A list of all authentication methods attached to this session. Use
|
|
986
|
+
* the information here to detect the last time a user verified a
|
|
987
|
+
* factor, for example if implementing a step-up scenario.
|
|
988
|
+
*/
|
|
989
|
+
currentAuthenticationMethods: AMREntry[]
|
|
990
|
+
}>
|
|
1034
991
|
|
|
1035
992
|
/**
|
|
1036
993
|
* Contains the full multi-factor authentication API.
|
|
@@ -1045,7 +1002,6 @@ export interface GoTrueMFAApi {
|
|
|
1045
1002
|
* The user has to enter the code from their authenticator app to verify it.
|
|
1046
1003
|
*
|
|
1047
1004
|
* Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to `aal2`.
|
|
1048
|
-
*
|
|
1049
1005
|
*/
|
|
1050
1006
|
enroll(params: MFAEnrollTOTPParams): Promise<AuthMFAEnrollTOTPResponse>
|
|
1051
1007
|
enroll(params: MFAEnrollPhoneParams): Promise<AuthMFAEnrollPhoneResponse>
|
|
@@ -1055,12 +1011,18 @@ export interface GoTrueMFAApi {
|
|
|
1055
1011
|
* Prepares a challenge used to verify that a user has access to a MFA
|
|
1056
1012
|
* factor.
|
|
1057
1013
|
*/
|
|
1058
|
-
challenge(params:
|
|
1014
|
+
challenge(params: MFAChallengeTOTPParams): Promise<Prettify<AuthMFAChallengeResponse<'totp'>>>
|
|
1015
|
+
challenge(params: MFAChallengePhoneParams): Promise<Prettify<AuthMFAChallengeResponse<'phone'>>>
|
|
1016
|
+
challenge(
|
|
1017
|
+
params: MFAChallengeParams
|
|
1018
|
+
): Promise<Prettify<AuthMFAChallengeResponse<'totp' | 'phone'>>>
|
|
1059
1019
|
|
|
1060
1020
|
/**
|
|
1061
1021
|
* Verifies a code against a challenge. The verification code is
|
|
1062
1022
|
* provided by the user by entering a code seen in their authenticator app.
|
|
1063
1023
|
*/
|
|
1024
|
+
verify(params: MFAVerifyTOTPParams): Promise<AuthMFAVerifyResponse>
|
|
1025
|
+
verify(params: MFAVerifyPhoneParams): Promise<AuthMFAVerifyResponse>
|
|
1064
1026
|
verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>
|
|
1065
1027
|
|
|
1066
1028
|
/**
|
|
@@ -1104,16 +1066,10 @@ export interface GoTrueMFAApi {
|
|
|
1104
1066
|
/**
|
|
1105
1067
|
* @expermental
|
|
1106
1068
|
*/
|
|
1107
|
-
export type AuthMFAAdminDeleteFactorResponse =
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
id: string
|
|
1112
|
-
}
|
|
1113
|
-
error: null
|
|
1114
|
-
}
|
|
1115
|
-
| { data: null; error: AuthError }
|
|
1116
|
-
|
|
1069
|
+
export type AuthMFAAdminDeleteFactorResponse = RequestResult<{
|
|
1070
|
+
/** ID of the factor that was successfully deleted. */
|
|
1071
|
+
id: string
|
|
1072
|
+
}>
|
|
1117
1073
|
/**
|
|
1118
1074
|
* @expermental
|
|
1119
1075
|
*/
|
|
@@ -1128,15 +1084,10 @@ export type AuthMFAAdminDeleteFactorParams = {
|
|
|
1128
1084
|
/**
|
|
1129
1085
|
* @expermental
|
|
1130
1086
|
*/
|
|
1131
|
-
export type AuthMFAAdminListFactorsResponse =
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
factors: Factor[]
|
|
1136
|
-
}
|
|
1137
|
-
error: null
|
|
1138
|
-
}
|
|
1139
|
-
| { data: null; error: AuthError }
|
|
1087
|
+
export type AuthMFAAdminListFactorsResponse = RequestResult<{
|
|
1088
|
+
/** All factors attached to the user. */
|
|
1089
|
+
factors: Factor[]
|
|
1090
|
+
}>
|
|
1140
1091
|
|
|
1141
1092
|
/**
|
|
1142
1093
|
* @expermental
|
|
@@ -1193,15 +1144,7 @@ export type SupportedStorage = PromisifyMethods<
|
|
|
1193
1144
|
|
|
1194
1145
|
export type InitializeResult = { error: AuthError | null }
|
|
1195
1146
|
|
|
1196
|
-
export type CallRefreshTokenResult =
|
|
1197
|
-
| {
|
|
1198
|
-
session: Session
|
|
1199
|
-
error: null
|
|
1200
|
-
}
|
|
1201
|
-
| {
|
|
1202
|
-
session: null
|
|
1203
|
-
error: AuthError
|
|
1204
|
-
}
|
|
1147
|
+
export type CallRefreshTokenResult = RequestResult<Session>
|
|
1205
1148
|
|
|
1206
1149
|
export type Pagination = {
|
|
1207
1150
|
[key: string]: any
|
|
@@ -1231,79 +1174,69 @@ export type SignOut = {
|
|
|
1231
1174
|
scope?: 'global' | 'local' | 'others'
|
|
1232
1175
|
}
|
|
1233
1176
|
|
|
1234
|
-
|
|
1177
|
+
type MFAEnrollParamsBase<T extends FactorType> = {
|
|
1235
1178
|
/** The type of factor being enrolled. */
|
|
1236
|
-
factorType:
|
|
1237
|
-
/** Domain which the user is enrolled with. */
|
|
1238
|
-
issuer?: string
|
|
1179
|
+
factorType: T
|
|
1239
1180
|
/** Human readable name assigned to the factor. */
|
|
1240
1181
|
friendlyName?: string
|
|
1241
1182
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1183
|
+
|
|
1184
|
+
type MFAEnrollTOTPParamFields = {
|
|
1185
|
+
/** Domain which the user is enrolled with. */
|
|
1186
|
+
issuer?: string
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
export type MFAEnrollTOTPParams = Prettify<MFAEnrollParamsBase<'totp'> & MFAEnrollTOTPParamFields>
|
|
1190
|
+
|
|
1191
|
+
type MFAEnrollPhoneParamFields = {
|
|
1247
1192
|
/** Phone number associated with a factor. Number should conform to E.164 format */
|
|
1248
1193
|
phone: string
|
|
1249
1194
|
}
|
|
1195
|
+
export type MFAEnrollPhoneParams = Prettify<
|
|
1196
|
+
MFAEnrollParamsBase<'phone'> & MFAEnrollPhoneParamFields
|
|
1197
|
+
>
|
|
1250
1198
|
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
/** ID of the factor that was just enrolled (in an unverified state). */
|
|
1255
|
-
id: string
|
|
1256
|
-
|
|
1257
|
-
/** Type of MFA factor.*/
|
|
1258
|
-
type: 'totp'
|
|
1259
|
-
|
|
1260
|
-
/** TOTP enrollment information. */
|
|
1261
|
-
totp: {
|
|
1262
|
-
/** Contains a QR code encoding the authenticator URI. You can
|
|
1263
|
-
* convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
|
|
1264
|
-
* the value. Avoid logging this value to the console. */
|
|
1265
|
-
qr_code: string
|
|
1266
|
-
|
|
1267
|
-
/** The TOTP secret (also encoded in the QR code). Show this secret
|
|
1268
|
-
* in a password-style field to the user, in case they are unable to
|
|
1269
|
-
* scan the QR code. Avoid logging this value to the console. */
|
|
1270
|
-
secret: string
|
|
1271
|
-
|
|
1272
|
-
/** The authenticator URI encoded within the QR code, should you need
|
|
1273
|
-
* to use it. Avoid loggin this value to the console. */
|
|
1274
|
-
uri: string
|
|
1275
|
-
}
|
|
1276
|
-
/** Friendly name of the factor, useful for distinguishing between factors **/
|
|
1277
|
-
friendly_name?: string
|
|
1278
|
-
}
|
|
1279
|
-
error: null
|
|
1280
|
-
}
|
|
1281
|
-
| {
|
|
1282
|
-
data: null
|
|
1283
|
-
error: AuthError
|
|
1284
|
-
}
|
|
1199
|
+
type AuthMFAEnrollResponseBase<T extends FactorType> = {
|
|
1200
|
+
/** ID of the factor that was just enrolled (in an unverified state). */
|
|
1201
|
+
id: string
|
|
1285
1202
|
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
data: {
|
|
1289
|
-
/** ID of the factor that was just enrolled (in an unverified state). */
|
|
1290
|
-
id: string
|
|
1203
|
+
/** Type of MFA factor.*/
|
|
1204
|
+
type: T
|
|
1291
1205
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1206
|
+
/** Friendly name of the factor, useful for distinguishing between factors **/
|
|
1207
|
+
friendly_name?: string
|
|
1208
|
+
}
|
|
1294
1209
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1210
|
+
type AuthMFAEnrollTOTPResponseFields = {
|
|
1211
|
+
/** TOTP enrollment information. */
|
|
1212
|
+
totp: {
|
|
1213
|
+
/** Contains a QR code encoding the authenticator URI. You can
|
|
1214
|
+
* convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
|
|
1215
|
+
* the value. Avoid logging this value to the console. */
|
|
1216
|
+
qr_code: string
|
|
1217
|
+
|
|
1218
|
+
/** The TOTP secret (also encoded in the QR code). Show this secret
|
|
1219
|
+
* in a password-style field to the user, in case they are unable to
|
|
1220
|
+
* scan the QR code. Avoid logging this value to the console. */
|
|
1221
|
+
secret: string
|
|
1222
|
+
|
|
1223
|
+
/** The authenticator URI encoded within the QR code, should you need
|
|
1224
|
+
* to use it. Avoid loggin this value to the console. */
|
|
1225
|
+
uri: string
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1297
1228
|
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1229
|
+
export type AuthMFAEnrollTOTPResponse = RequestResult<
|
|
1230
|
+
Prettify<AuthMFAEnrollResponseBase<'totp'> & AuthMFAEnrollTOTPResponseFields>
|
|
1231
|
+
>
|
|
1232
|
+
|
|
1233
|
+
type AuthMFAEnrollPhoneResponseFields = {
|
|
1234
|
+
/** Phone number of the MFA factor in E.164 format. Used to send messages */
|
|
1235
|
+
phone: string
|
|
1236
|
+
}
|
|
1237
|
+
export type AuthMFAEnrollPhoneResponse = RequestResult<
|
|
1238
|
+
Prettify<AuthMFAEnrollResponseBase<'phone'> & AuthMFAEnrollPhoneResponseFields>
|
|
1239
|
+
>
|
|
1307
1240
|
|
|
1308
1241
|
export type JwtHeader = {
|
|
1309
1242
|
alg: 'RS256' | 'ES256' | 'HS256'
|