@authsome/ui-core 0.1.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.
- package/README.md +164 -0
- package/dist/adapters/index.d.mts +57 -0
- package/dist/adapters/index.d.ts +57 -0
- package/dist/adapters/index.js +94 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +92 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/index.d.mts +540 -0
- package/dist/index.d.ts +540 -0
- package/dist/index.js +1453 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1415 -0
- package/dist/index.mjs.map +1 -0
- package/dist/provider-DXf_a2WT.d.mts +457 -0
- package/dist/provider-DXf_a2WT.d.ts +457 -0
- package/dist/types/index.d.mts +98 -0
- package/dist/types/index.d.ts +98 -0
- package/dist/types/index.js +180 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +170 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +57 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1453 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/types/auth.ts
|
|
4
|
+
var AuthState = /* @__PURE__ */ ((AuthState2) => {
|
|
5
|
+
AuthState2["AUTHENTICATED"] = "authenticated";
|
|
6
|
+
AuthState2["UNAUTHENTICATED"] = "unauthenticated";
|
|
7
|
+
AuthState2["LOADING"] = "loading";
|
|
8
|
+
AuthState2["ERROR"] = "error";
|
|
9
|
+
return AuthState2;
|
|
10
|
+
})(AuthState || {});
|
|
11
|
+
var AuthErrorType = /* @__PURE__ */ ((AuthErrorType2) => {
|
|
12
|
+
AuthErrorType2["INVALID_CREDENTIALS"] = "invalid_credentials";
|
|
13
|
+
AuthErrorType2["USER_NOT_FOUND"] = "user_not_found";
|
|
14
|
+
AuthErrorType2["USER_ALREADY_EXISTS"] = "user_already_exists";
|
|
15
|
+
AuthErrorType2["INVALID_TOKEN"] = "invalid_token";
|
|
16
|
+
AuthErrorType2["TOKEN_EXPIRED"] = "token_expired";
|
|
17
|
+
AuthErrorType2["NETWORK_ERROR"] = "network_error";
|
|
18
|
+
AuthErrorType2["VALIDATION_ERROR"] = "validation_error";
|
|
19
|
+
AuthErrorType2["MFA_REQUIRED"] = "mfa_required";
|
|
20
|
+
AuthErrorType2["EMAIL_NOT_VERIFIED"] = "email_not_verified";
|
|
21
|
+
AuthErrorType2["PHONE_NOT_VERIFIED"] = "phone_not_verified";
|
|
22
|
+
AuthErrorType2["RATE_LIMIT_EXCEEDED"] = "rate_limit_exceeded";
|
|
23
|
+
AuthErrorType2["UNKNOWN_ERROR"] = "unknown_error";
|
|
24
|
+
return AuthErrorType2;
|
|
25
|
+
})(AuthErrorType || {});
|
|
26
|
+
var AuthError = class _AuthError extends Error {
|
|
27
|
+
constructor(message, type = "unknown_error" /* UNKNOWN_ERROR */, options) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = "AuthError";
|
|
30
|
+
this.type = type;
|
|
31
|
+
this.details = options?.details;
|
|
32
|
+
this.code = options?.code;
|
|
33
|
+
this.originalError = options?.originalError;
|
|
34
|
+
if (Error.captureStackTrace) {
|
|
35
|
+
Error.captureStackTrace(this, _AuthError);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var OAuthProvider = /* @__PURE__ */ ((OAuthProvider2) => {
|
|
40
|
+
OAuthProvider2["GOOGLE"] = "google";
|
|
41
|
+
OAuthProvider2["GITHUB"] = "github";
|
|
42
|
+
OAuthProvider2["FACEBOOK"] = "facebook";
|
|
43
|
+
OAuthProvider2["TWITTER"] = "twitter";
|
|
44
|
+
OAuthProvider2["MICROSOFT"] = "microsoft";
|
|
45
|
+
OAuthProvider2["APPLE"] = "apple";
|
|
46
|
+
OAuthProvider2["LINKEDIN"] = "linkedin";
|
|
47
|
+
OAuthProvider2["DISCORD"] = "discord";
|
|
48
|
+
return OAuthProvider2;
|
|
49
|
+
})(OAuthProvider || {});
|
|
50
|
+
var TwoFactorMethod = /* @__PURE__ */ ((TwoFactorMethod2) => {
|
|
51
|
+
TwoFactorMethod2["TOTP"] = "totp";
|
|
52
|
+
TwoFactorMethod2["SMS"] = "sms";
|
|
53
|
+
TwoFactorMethod2["EMAIL"] = "email";
|
|
54
|
+
TwoFactorMethod2["BACKUP_CODE"] = "backup_code";
|
|
55
|
+
return TwoFactorMethod2;
|
|
56
|
+
})(TwoFactorMethod || {});
|
|
57
|
+
|
|
58
|
+
// src/types/storage.ts
|
|
59
|
+
var LocalStorageAdapter = class {
|
|
60
|
+
getItem(key) {
|
|
61
|
+
if (typeof window === "undefined") return null;
|
|
62
|
+
return window.localStorage.getItem(key);
|
|
63
|
+
}
|
|
64
|
+
setItem(key, value) {
|
|
65
|
+
if (typeof window === "undefined") return;
|
|
66
|
+
window.localStorage.setItem(key, value);
|
|
67
|
+
}
|
|
68
|
+
removeItem(key) {
|
|
69
|
+
if (typeof window === "undefined") return;
|
|
70
|
+
window.localStorage.removeItem(key);
|
|
71
|
+
}
|
|
72
|
+
clear() {
|
|
73
|
+
if (typeof window === "undefined") return;
|
|
74
|
+
window.localStorage.clear();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var SessionStorageAdapter = class {
|
|
78
|
+
getItem(key) {
|
|
79
|
+
if (typeof window === "undefined") return null;
|
|
80
|
+
return window.sessionStorage.getItem(key);
|
|
81
|
+
}
|
|
82
|
+
setItem(key, value) {
|
|
83
|
+
if (typeof window === "undefined") return;
|
|
84
|
+
window.sessionStorage.setItem(key, value);
|
|
85
|
+
}
|
|
86
|
+
removeItem(key) {
|
|
87
|
+
if (typeof window === "undefined") return;
|
|
88
|
+
window.sessionStorage.removeItem(key);
|
|
89
|
+
}
|
|
90
|
+
clear() {
|
|
91
|
+
if (typeof window === "undefined") return;
|
|
92
|
+
window.sessionStorage.clear();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var MemoryStorageAdapter = class {
|
|
96
|
+
constructor() {
|
|
97
|
+
this.store = /* @__PURE__ */ new Map();
|
|
98
|
+
}
|
|
99
|
+
getItem(key) {
|
|
100
|
+
return this.store.get(key) ?? null;
|
|
101
|
+
}
|
|
102
|
+
setItem(key, value) {
|
|
103
|
+
this.store.set(key, value);
|
|
104
|
+
}
|
|
105
|
+
removeItem(key) {
|
|
106
|
+
this.store.delete(key);
|
|
107
|
+
}
|
|
108
|
+
clear() {
|
|
109
|
+
this.store.clear();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/types/observable.ts
|
|
114
|
+
var Observable = class {
|
|
115
|
+
constructor(initialValue) {
|
|
116
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
117
|
+
this.value = initialValue;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get current value
|
|
121
|
+
*/
|
|
122
|
+
getValue() {
|
|
123
|
+
return this.value;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Set new value and notify listeners
|
|
127
|
+
*/
|
|
128
|
+
setValue(newValue) {
|
|
129
|
+
if (this.value !== newValue) {
|
|
130
|
+
this.value = newValue;
|
|
131
|
+
this.notify();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Update value with a function
|
|
136
|
+
*/
|
|
137
|
+
update(updater) {
|
|
138
|
+
this.setValue(updater(this.value));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Subscribe to value changes
|
|
142
|
+
*/
|
|
143
|
+
subscribe(listener) {
|
|
144
|
+
this.listeners.add(listener);
|
|
145
|
+
listener(this.value);
|
|
146
|
+
return () => {
|
|
147
|
+
this.listeners.delete(listener);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Notify all listeners
|
|
152
|
+
*/
|
|
153
|
+
notify() {
|
|
154
|
+
this.listeners.forEach((listener) => listener(this.value));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Clear all listeners
|
|
158
|
+
*/
|
|
159
|
+
clearListeners() {
|
|
160
|
+
this.listeners.clear();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get number of listeners
|
|
164
|
+
*/
|
|
165
|
+
getListenerCount() {
|
|
166
|
+
return this.listeners.size;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/utils/errors.ts
|
|
171
|
+
function createAuthError(type, message, details, code) {
|
|
172
|
+
return new AuthError(message, type, { details, code });
|
|
173
|
+
}
|
|
174
|
+
function isAuthError(error) {
|
|
175
|
+
return error instanceof AuthError;
|
|
176
|
+
}
|
|
177
|
+
function toAuthError(error) {
|
|
178
|
+
if (isAuthError(error)) {
|
|
179
|
+
return error;
|
|
180
|
+
}
|
|
181
|
+
if (error instanceof Error) {
|
|
182
|
+
return new AuthError(error.message, "unknown_error" /* UNKNOWN_ERROR */, {
|
|
183
|
+
details: {
|
|
184
|
+
originalError: error.name,
|
|
185
|
+
stack: error.stack
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (typeof error === "string") {
|
|
190
|
+
return new AuthError(error, "unknown_error" /* UNKNOWN_ERROR */);
|
|
191
|
+
}
|
|
192
|
+
return new AuthError(
|
|
193
|
+
"An unknown error occurred",
|
|
194
|
+
"unknown_error" /* UNKNOWN_ERROR */,
|
|
195
|
+
{ details: { error } }
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
function isNetworkError(error) {
|
|
199
|
+
if (error instanceof Error) {
|
|
200
|
+
return error.name === "NetworkError" || error.message.includes("network") || error.message.includes("fetch");
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
function isUnauthenticatedError(error) {
|
|
205
|
+
if (isAuthError(error)) {
|
|
206
|
+
return error.type === "invalid_token" /* INVALID_TOKEN */ || error.type === "token_expired" /* TOKEN_EXPIRED */;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
function isMFARequiredError(error) {
|
|
211
|
+
if (isAuthError(error)) {
|
|
212
|
+
return error.type === "mfa_required" /* MFA_REQUIRED */;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/utils/validation.ts
|
|
218
|
+
var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
219
|
+
var PHONE_REGEX = /^\+?[1-9]\d{1,14}$/;
|
|
220
|
+
var USERNAME_REGEX = /^[a-zA-Z0-9_-]{3,30}$/;
|
|
221
|
+
function validateEmail(email) {
|
|
222
|
+
if (!email) {
|
|
223
|
+
return { field: "email", message: "Email is required" };
|
|
224
|
+
}
|
|
225
|
+
if (!EMAIL_REGEX.test(email)) {
|
|
226
|
+
return { field: "email", message: "Invalid email address" };
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
function validatePassword(password, options = {}) {
|
|
231
|
+
const {
|
|
232
|
+
minLength = 8,
|
|
233
|
+
requireUppercase = true,
|
|
234
|
+
requireLowercase = true,
|
|
235
|
+
requireNumber = true,
|
|
236
|
+
requireSpecial = false
|
|
237
|
+
} = options;
|
|
238
|
+
if (!password) {
|
|
239
|
+
return { field: "password", message: "Password is required" };
|
|
240
|
+
}
|
|
241
|
+
if (password.length < minLength) {
|
|
242
|
+
return {
|
|
243
|
+
field: "password",
|
|
244
|
+
message: `Password must be at least ${minLength} characters`
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
if (requireUppercase && !/[A-Z]/.test(password)) {
|
|
248
|
+
return {
|
|
249
|
+
field: "password",
|
|
250
|
+
message: "Password must contain at least one uppercase letter"
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (requireLowercase && !/[a-z]/.test(password)) {
|
|
254
|
+
return {
|
|
255
|
+
field: "password",
|
|
256
|
+
message: "Password must contain at least one lowercase letter"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (requireNumber && !/\d/.test(password)) {
|
|
260
|
+
return { field: "password", message: "Password must contain at least one number" };
|
|
261
|
+
}
|
|
262
|
+
if (requireSpecial && !/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
|
|
263
|
+
return {
|
|
264
|
+
field: "password",
|
|
265
|
+
message: "Password must contain at least one special character"
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
function validatePhone(phone) {
|
|
271
|
+
if (!phone) {
|
|
272
|
+
return { field: "phone", message: "Phone number is required" };
|
|
273
|
+
}
|
|
274
|
+
if (!PHONE_REGEX.test(phone)) {
|
|
275
|
+
return {
|
|
276
|
+
field: "phone",
|
|
277
|
+
message: "Invalid phone number. Use international format (+1234567890)"
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
function validateUsername(username) {
|
|
283
|
+
if (!username) {
|
|
284
|
+
return { field: "username", message: "Username is required" };
|
|
285
|
+
}
|
|
286
|
+
if (!USERNAME_REGEX.test(username)) {
|
|
287
|
+
return {
|
|
288
|
+
field: "username",
|
|
289
|
+
message: "Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
function validate2FACode(code) {
|
|
295
|
+
if (!code) {
|
|
296
|
+
return { field: "code", message: "Verification code is required" };
|
|
297
|
+
}
|
|
298
|
+
if (!/^\d{6}$/.test(code)) {
|
|
299
|
+
return { field: "code", message: "Code must be 6 digits" };
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
function validateRequired(value, fieldName) {
|
|
304
|
+
if (!value || typeof value === "string" && !value.trim()) {
|
|
305
|
+
return { field: fieldName, message: `${fieldName} is required` };
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/utils/tokens.ts
|
|
311
|
+
var TOKEN_KEY = "authsome_token";
|
|
312
|
+
var REFRESH_TOKEN_KEY = "authsome_refresh_token";
|
|
313
|
+
var TokenManager = class {
|
|
314
|
+
constructor(storage = new LocalStorageAdapter()) {
|
|
315
|
+
this.storage = storage;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get access token
|
|
319
|
+
*/
|
|
320
|
+
async getToken() {
|
|
321
|
+
return await Promise.resolve(this.storage.getItem(TOKEN_KEY));
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Set access token
|
|
325
|
+
*/
|
|
326
|
+
async setToken(token) {
|
|
327
|
+
await Promise.resolve(this.storage.setItem(TOKEN_KEY, token));
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Remove access token
|
|
331
|
+
*/
|
|
332
|
+
async removeToken() {
|
|
333
|
+
await Promise.resolve(this.storage.removeItem(TOKEN_KEY));
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Get refresh token
|
|
337
|
+
*/
|
|
338
|
+
async getRefreshToken() {
|
|
339
|
+
return await Promise.resolve(this.storage.getItem(REFRESH_TOKEN_KEY));
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Set refresh token
|
|
343
|
+
*/
|
|
344
|
+
async setRefreshToken(token) {
|
|
345
|
+
await Promise.resolve(this.storage.setItem(REFRESH_TOKEN_KEY, token));
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Remove refresh token
|
|
349
|
+
*/
|
|
350
|
+
async removeRefreshToken() {
|
|
351
|
+
await Promise.resolve(this.storage.removeItem(REFRESH_TOKEN_KEY));
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Clear all tokens
|
|
355
|
+
*/
|
|
356
|
+
async clearTokens() {
|
|
357
|
+
await this.removeToken();
|
|
358
|
+
await this.removeRefreshToken();
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Check if token is expired
|
|
362
|
+
*/
|
|
363
|
+
isTokenExpired(token) {
|
|
364
|
+
try {
|
|
365
|
+
const payload = this.decodeToken(token);
|
|
366
|
+
if (!payload.exp) return false;
|
|
367
|
+
const expiresAt = payload.exp * 1e3;
|
|
368
|
+
const now = Date.now();
|
|
369
|
+
return expiresAt - now < 6e4;
|
|
370
|
+
} catch {
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Decode JWT token (without verification)
|
|
376
|
+
*/
|
|
377
|
+
decodeToken(token) {
|
|
378
|
+
const parts = token.split(".");
|
|
379
|
+
if (parts.length !== 3) {
|
|
380
|
+
throw new Error("Invalid token format");
|
|
381
|
+
}
|
|
382
|
+
const payload = parts[1];
|
|
383
|
+
const decoded = atob(payload);
|
|
384
|
+
return JSON.parse(decoded);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/adapters/base-provider.ts
|
|
389
|
+
var BaseAuthProvider = class {
|
|
390
|
+
constructor() {
|
|
391
|
+
this.config = {};
|
|
392
|
+
this.initialized = false;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Initialize the provider
|
|
396
|
+
*/
|
|
397
|
+
async initialize(config) {
|
|
398
|
+
this.config = config;
|
|
399
|
+
this.initialized = true;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Ensure provider is initialized
|
|
403
|
+
*/
|
|
404
|
+
ensureInitialized() {
|
|
405
|
+
if (!this.initialized) {
|
|
406
|
+
throw new Error(`Provider ${this.name} is not initialized`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Make HTTP request
|
|
411
|
+
*/
|
|
412
|
+
async request(url, options = {}) {
|
|
413
|
+
const response = await fetch(url, {
|
|
414
|
+
...options,
|
|
415
|
+
headers: {
|
|
416
|
+
"Content-Type": "application/json",
|
|
417
|
+
...options.headers
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
if (!response.ok) {
|
|
421
|
+
const error = await response.json().catch(() => ({
|
|
422
|
+
message: response.statusText
|
|
423
|
+
}));
|
|
424
|
+
throw error;
|
|
425
|
+
}
|
|
426
|
+
return response.json();
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Normalize error to AuthError
|
|
430
|
+
*/
|
|
431
|
+
normalizeError(error) {
|
|
432
|
+
return toAuthError(error);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
// src/client.ts
|
|
437
|
+
var AuthClient = class {
|
|
438
|
+
constructor(config) {
|
|
439
|
+
this.provider = config.provider;
|
|
440
|
+
this.autoRefresh = config.autoRefresh ?? true;
|
|
441
|
+
this.refreshInterval = config.refreshInterval ?? 5 * 60 * 1e3;
|
|
442
|
+
this.state = new Observable({
|
|
443
|
+
state: "loading" /* LOADING */,
|
|
444
|
+
user: null,
|
|
445
|
+
session: null,
|
|
446
|
+
error: null,
|
|
447
|
+
isAuthenticated: false,
|
|
448
|
+
isLoading: true
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Initialize the auth client
|
|
453
|
+
*/
|
|
454
|
+
async initialize() {
|
|
455
|
+
try {
|
|
456
|
+
const user = await this.provider.getCurrentUser();
|
|
457
|
+
const session = await this.provider.getCurrentSession();
|
|
458
|
+
if (user && session) {
|
|
459
|
+
this.updateState({
|
|
460
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
461
|
+
user,
|
|
462
|
+
session,
|
|
463
|
+
error: null,
|
|
464
|
+
isAuthenticated: true,
|
|
465
|
+
isLoading: false
|
|
466
|
+
});
|
|
467
|
+
if (this.autoRefresh) {
|
|
468
|
+
this.startAutoRefresh();
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
this.updateState({
|
|
472
|
+
state: "unauthenticated" /* UNAUTHENTICATED */,
|
|
473
|
+
user: null,
|
|
474
|
+
session: null,
|
|
475
|
+
error: null,
|
|
476
|
+
isAuthenticated: false,
|
|
477
|
+
isLoading: false
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
} catch (error) {
|
|
481
|
+
this.handleError(error);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Sign in with credentials
|
|
486
|
+
*/
|
|
487
|
+
async signIn(request) {
|
|
488
|
+
try {
|
|
489
|
+
this.setLoading();
|
|
490
|
+
const response = await this.provider.signIn(request);
|
|
491
|
+
if (response.requiresTwoFactor) {
|
|
492
|
+
this.updateState({
|
|
493
|
+
state: "unauthenticated" /* UNAUTHENTICATED */,
|
|
494
|
+
user: response.user,
|
|
495
|
+
session: null,
|
|
496
|
+
error: null,
|
|
497
|
+
isAuthenticated: false,
|
|
498
|
+
isLoading: false
|
|
499
|
+
});
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
this.updateState({
|
|
503
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
504
|
+
user: response.user,
|
|
505
|
+
session: response.session,
|
|
506
|
+
error: null,
|
|
507
|
+
isAuthenticated: true,
|
|
508
|
+
isLoading: false
|
|
509
|
+
});
|
|
510
|
+
if (this.autoRefresh) {
|
|
511
|
+
this.startAutoRefresh();
|
|
512
|
+
}
|
|
513
|
+
} catch (error) {
|
|
514
|
+
this.handleError(error);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Sign up with credentials
|
|
519
|
+
*/
|
|
520
|
+
async signUp(request) {
|
|
521
|
+
try {
|
|
522
|
+
this.setLoading();
|
|
523
|
+
const response = await this.provider.signUp(request);
|
|
524
|
+
this.updateState({
|
|
525
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
526
|
+
user: response.user,
|
|
527
|
+
session: response.session,
|
|
528
|
+
error: null,
|
|
529
|
+
isAuthenticated: true,
|
|
530
|
+
isLoading: false
|
|
531
|
+
});
|
|
532
|
+
if (this.autoRefresh) {
|
|
533
|
+
this.startAutoRefresh();
|
|
534
|
+
}
|
|
535
|
+
} catch (error) {
|
|
536
|
+
this.handleError(error);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Sign out
|
|
541
|
+
*/
|
|
542
|
+
async signOut() {
|
|
543
|
+
try {
|
|
544
|
+
this.stopAutoRefresh();
|
|
545
|
+
await this.provider.signOut();
|
|
546
|
+
this.updateState({
|
|
547
|
+
state: "unauthenticated" /* UNAUTHENTICATED */,
|
|
548
|
+
user: null,
|
|
549
|
+
session: null,
|
|
550
|
+
error: null,
|
|
551
|
+
isAuthenticated: false,
|
|
552
|
+
isLoading: false
|
|
553
|
+
});
|
|
554
|
+
} catch (error) {
|
|
555
|
+
this.handleError(error);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Update user profile
|
|
560
|
+
*/
|
|
561
|
+
async updateUser(request) {
|
|
562
|
+
try {
|
|
563
|
+
const user = await this.provider.updateUser(request);
|
|
564
|
+
const currentState = this.state.getValue();
|
|
565
|
+
this.updateState({
|
|
566
|
+
...currentState,
|
|
567
|
+
user
|
|
568
|
+
});
|
|
569
|
+
} catch (error) {
|
|
570
|
+
this.handleError(error);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Change password
|
|
575
|
+
*/
|
|
576
|
+
async changePassword(request) {
|
|
577
|
+
try {
|
|
578
|
+
await this.provider.changePassword(request);
|
|
579
|
+
} catch (error) {
|
|
580
|
+
throw this.provider.normalizeError(error);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Request password reset
|
|
585
|
+
*/
|
|
586
|
+
async requestPasswordReset(request) {
|
|
587
|
+
try {
|
|
588
|
+
await this.provider.requestPasswordReset(request);
|
|
589
|
+
} catch (error) {
|
|
590
|
+
throw this.provider.normalizeError(error);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Confirm password reset
|
|
595
|
+
*/
|
|
596
|
+
async confirmPasswordReset(request) {
|
|
597
|
+
try {
|
|
598
|
+
await this.provider.confirmPasswordReset(request);
|
|
599
|
+
} catch (error) {
|
|
600
|
+
throw this.provider.normalizeError(error);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Get OAuth sign in URL
|
|
605
|
+
*/
|
|
606
|
+
async getOAuthUrl(request) {
|
|
607
|
+
return this.provider.oauthSignIn(request);
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Handle OAuth callback
|
|
611
|
+
*/
|
|
612
|
+
async handleOAuthCallback(request) {
|
|
613
|
+
try {
|
|
614
|
+
this.setLoading();
|
|
615
|
+
const response = await this.provider.oauthCallback(request);
|
|
616
|
+
this.updateState({
|
|
617
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
618
|
+
user: response.user,
|
|
619
|
+
session: response.session,
|
|
620
|
+
error: null,
|
|
621
|
+
isAuthenticated: true,
|
|
622
|
+
isLoading: false
|
|
623
|
+
});
|
|
624
|
+
if (this.autoRefresh) {
|
|
625
|
+
this.startAutoRefresh();
|
|
626
|
+
}
|
|
627
|
+
} catch (error) {
|
|
628
|
+
this.handleError(error);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Get available OAuth providers
|
|
633
|
+
*/
|
|
634
|
+
async getOAuthProviders() {
|
|
635
|
+
return this.provider.getOAuthProviders();
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Send magic link
|
|
639
|
+
*/
|
|
640
|
+
async sendMagicLink(request) {
|
|
641
|
+
try {
|
|
642
|
+
await this.provider.sendMagicLink(request);
|
|
643
|
+
} catch (error) {
|
|
644
|
+
throw this.provider.normalizeError(error);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Verify magic link
|
|
649
|
+
*/
|
|
650
|
+
async verifyMagicLink(request) {
|
|
651
|
+
try {
|
|
652
|
+
this.setLoading();
|
|
653
|
+
const response = await this.provider.verifyMagicLink(request);
|
|
654
|
+
this.updateState({
|
|
655
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
656
|
+
user: response.user,
|
|
657
|
+
session: response.session,
|
|
658
|
+
error: null,
|
|
659
|
+
isAuthenticated: true,
|
|
660
|
+
isLoading: false
|
|
661
|
+
});
|
|
662
|
+
if (this.autoRefresh) {
|
|
663
|
+
this.startAutoRefresh();
|
|
664
|
+
}
|
|
665
|
+
} catch (error) {
|
|
666
|
+
this.handleError(error);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Send phone verification code
|
|
671
|
+
*/
|
|
672
|
+
async sendPhoneCode(request) {
|
|
673
|
+
try {
|
|
674
|
+
await this.provider.sendPhoneCode(request);
|
|
675
|
+
} catch (error) {
|
|
676
|
+
throw this.provider.normalizeError(error);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Verify phone code
|
|
681
|
+
*/
|
|
682
|
+
async verifyPhoneCode(request) {
|
|
683
|
+
try {
|
|
684
|
+
this.setLoading();
|
|
685
|
+
const response = await this.provider.verifyPhoneCode(request);
|
|
686
|
+
this.updateState({
|
|
687
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
688
|
+
user: response.user,
|
|
689
|
+
session: response.session,
|
|
690
|
+
error: null,
|
|
691
|
+
isAuthenticated: true,
|
|
692
|
+
isLoading: false
|
|
693
|
+
});
|
|
694
|
+
if (this.autoRefresh) {
|
|
695
|
+
this.startAutoRefresh();
|
|
696
|
+
}
|
|
697
|
+
} catch (error) {
|
|
698
|
+
this.handleError(error);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Setup 2FA
|
|
703
|
+
*/
|
|
704
|
+
async setupTwoFactor(request) {
|
|
705
|
+
return this.provider.setupTwoFactor(request);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Verify 2FA code
|
|
709
|
+
*/
|
|
710
|
+
async verifyTwoFactor(request) {
|
|
711
|
+
try {
|
|
712
|
+
this.setLoading();
|
|
713
|
+
const response = await this.provider.verifyTwoFactor(request);
|
|
714
|
+
this.updateState({
|
|
715
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
716
|
+
user: response.user,
|
|
717
|
+
session: response.session,
|
|
718
|
+
error: null,
|
|
719
|
+
isAuthenticated: true,
|
|
720
|
+
isLoading: false
|
|
721
|
+
});
|
|
722
|
+
if (this.autoRefresh) {
|
|
723
|
+
this.startAutoRefresh();
|
|
724
|
+
}
|
|
725
|
+
} catch (error) {
|
|
726
|
+
this.handleError(error);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Disable 2FA
|
|
731
|
+
*/
|
|
732
|
+
async disableTwoFactor() {
|
|
733
|
+
return this.provider.disableTwoFactor();
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Get 2FA status
|
|
737
|
+
*/
|
|
738
|
+
async getTwoFactorStatus() {
|
|
739
|
+
return this.provider.getTwoFactorStatus();
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Register passkey
|
|
743
|
+
*/
|
|
744
|
+
async registerPasskey(request) {
|
|
745
|
+
return this.provider.registerPasskey(request);
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Authenticate with passkey
|
|
749
|
+
*/
|
|
750
|
+
async authenticatePasskey(request) {
|
|
751
|
+
try {
|
|
752
|
+
this.setLoading();
|
|
753
|
+
const response = await this.provider.authenticatePasskey(request);
|
|
754
|
+
this.updateState({
|
|
755
|
+
state: "authenticated" /* AUTHENTICATED */,
|
|
756
|
+
user: response.user,
|
|
757
|
+
session: response.session,
|
|
758
|
+
error: null,
|
|
759
|
+
isAuthenticated: true,
|
|
760
|
+
isLoading: false
|
|
761
|
+
});
|
|
762
|
+
if (this.autoRefresh) {
|
|
763
|
+
this.startAutoRefresh();
|
|
764
|
+
}
|
|
765
|
+
} catch (error) {
|
|
766
|
+
this.handleError(error);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* List passkeys
|
|
771
|
+
*/
|
|
772
|
+
async listPasskeys() {
|
|
773
|
+
return this.provider.listPasskeys();
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Delete passkey
|
|
777
|
+
*/
|
|
778
|
+
async deletePasskey(credentialId) {
|
|
779
|
+
return this.provider.deletePasskey(credentialId);
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Get all organizations the user belongs to
|
|
783
|
+
* Only available if the provider supports organizations
|
|
784
|
+
*/
|
|
785
|
+
async getOrganizations() {
|
|
786
|
+
if (!this.provider.getOrganizations) {
|
|
787
|
+
throw this.createUnsupportedError("Organization support");
|
|
788
|
+
}
|
|
789
|
+
return this.provider.getOrganizations();
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Get the currently active organization
|
|
793
|
+
* Only available if the provider supports organizations
|
|
794
|
+
*/
|
|
795
|
+
async getActiveOrganization() {
|
|
796
|
+
if (!this.provider.getActiveOrganization) {
|
|
797
|
+
throw this.createUnsupportedError("Organization support");
|
|
798
|
+
}
|
|
799
|
+
return this.provider.getActiveOrganization();
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Set the active organization and refresh user state
|
|
803
|
+
* Only available if the provider supports organizations
|
|
804
|
+
*/
|
|
805
|
+
async setActiveOrganization(organizationId) {
|
|
806
|
+
if (!this.provider.setActiveOrganization) {
|
|
807
|
+
throw this.createUnsupportedError("Organization support");
|
|
808
|
+
}
|
|
809
|
+
await this.provider.setActiveOrganization(organizationId);
|
|
810
|
+
await this.refreshSession();
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Get organization memberships with roles and permissions
|
|
814
|
+
* Only available if the provider supports organizations
|
|
815
|
+
*/
|
|
816
|
+
async getOrganizationMemberships() {
|
|
817
|
+
if (!this.provider.getOrganizationMemberships) {
|
|
818
|
+
throw this.createUnsupportedError("Organization memberships");
|
|
819
|
+
}
|
|
820
|
+
return this.provider.getOrganizationMemberships();
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Check if the provider supports organizations
|
|
824
|
+
*/
|
|
825
|
+
supportsOrganizations() {
|
|
826
|
+
return !!(this.provider.getOrganizations && this.provider.getActiveOrganization && this.provider.setActiveOrganization);
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Refresh session
|
|
830
|
+
*/
|
|
831
|
+
async refreshSession() {
|
|
832
|
+
try {
|
|
833
|
+
const session = await this.provider.refreshSession();
|
|
834
|
+
const currentState = this.state.getValue();
|
|
835
|
+
this.updateState({
|
|
836
|
+
...currentState,
|
|
837
|
+
session
|
|
838
|
+
});
|
|
839
|
+
} catch (error) {
|
|
840
|
+
await this.signOut();
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Get current user
|
|
845
|
+
*/
|
|
846
|
+
getUser() {
|
|
847
|
+
return this.state.getValue().user;
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Get current session
|
|
851
|
+
*/
|
|
852
|
+
getSession() {
|
|
853
|
+
return this.state.getValue().session;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Check if authenticated
|
|
857
|
+
*/
|
|
858
|
+
isAuthenticated() {
|
|
859
|
+
return this.state.getValue().isAuthenticated;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Get current error
|
|
863
|
+
*/
|
|
864
|
+
getError() {
|
|
865
|
+
return this.state.getValue().error;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Clear error
|
|
869
|
+
*/
|
|
870
|
+
clearError() {
|
|
871
|
+
const currentState = this.state.getValue();
|
|
872
|
+
this.updateState({
|
|
873
|
+
...currentState,
|
|
874
|
+
error: null
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Subscribe to auth state changes
|
|
879
|
+
*/
|
|
880
|
+
subscribe(listener) {
|
|
881
|
+
return this.state.subscribe(listener);
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Cleanup resources
|
|
885
|
+
*/
|
|
886
|
+
destroy() {
|
|
887
|
+
this.stopAutoRefresh();
|
|
888
|
+
this.state.clearListeners();
|
|
889
|
+
}
|
|
890
|
+
// Private methods
|
|
891
|
+
updateState(newState) {
|
|
892
|
+
this.state.setValue(newState);
|
|
893
|
+
}
|
|
894
|
+
setLoading() {
|
|
895
|
+
const currentState = this.state.getValue();
|
|
896
|
+
this.updateState({
|
|
897
|
+
...currentState,
|
|
898
|
+
state: "loading" /* LOADING */,
|
|
899
|
+
isLoading: true,
|
|
900
|
+
error: null
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
handleError(error) {
|
|
904
|
+
const authError = this.provider.normalizeError(error);
|
|
905
|
+
const currentState = this.state.getValue();
|
|
906
|
+
this.updateState({
|
|
907
|
+
...currentState,
|
|
908
|
+
state: "error" /* ERROR */,
|
|
909
|
+
error: authError,
|
|
910
|
+
isLoading: false
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
startAutoRefresh() {
|
|
914
|
+
this.stopAutoRefresh();
|
|
915
|
+
this.refreshTimer = setInterval(() => {
|
|
916
|
+
this.refreshSession();
|
|
917
|
+
}, this.refreshInterval);
|
|
918
|
+
}
|
|
919
|
+
stopAutoRefresh() {
|
|
920
|
+
if (this.refreshTimer) {
|
|
921
|
+
clearInterval(this.refreshTimer);
|
|
922
|
+
this.refreshTimer = void 0;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
createUnsupportedError(feature) {
|
|
926
|
+
return {
|
|
927
|
+
name: "AuthError",
|
|
928
|
+
message: `${feature} is not available with this auth provider`,
|
|
929
|
+
type: "unknown_error" /* UNKNOWN_ERROR */
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
// src/flows/types.ts
|
|
935
|
+
var FlowStep = /* @__PURE__ */ ((FlowStep2) => {
|
|
936
|
+
FlowStep2["SIGN_IN"] = "sign_in";
|
|
937
|
+
FlowStep2["SIGN_UP"] = "sign_up";
|
|
938
|
+
FlowStep2["EMAIL_PASSWORD_SIGN_IN"] = "email_password_sign_in";
|
|
939
|
+
FlowStep2["EMAIL_PASSWORD_SIGN_UP"] = "email_password_sign_up";
|
|
940
|
+
FlowStep2["OAUTH_SELECT"] = "oauth_select";
|
|
941
|
+
FlowStep2["OAUTH_CALLBACK"] = "oauth_callback";
|
|
942
|
+
FlowStep2["MAGIC_LINK_REQUEST"] = "magic_link_request";
|
|
943
|
+
FlowStep2["MAGIC_LINK_VERIFY"] = "magic_link_verify";
|
|
944
|
+
FlowStep2["MAGIC_LINK_SENT"] = "magic_link_sent";
|
|
945
|
+
FlowStep2["PHONE_REQUEST"] = "phone_request";
|
|
946
|
+
FlowStep2["PHONE_VERIFY"] = "phone_verify";
|
|
947
|
+
FlowStep2["USERNAME_SIGN_IN"] = "username_sign_in";
|
|
948
|
+
FlowStep2["USERNAME_SIGN_UP"] = "username_sign_up";
|
|
949
|
+
FlowStep2["PASSKEY_REGISTER"] = "passkey_register";
|
|
950
|
+
FlowStep2["PASSKEY_AUTHENTICATE"] = "passkey_authenticate";
|
|
951
|
+
FlowStep2["MFA_REQUIRED"] = "mfa_required";
|
|
952
|
+
FlowStep2["MFA_SETUP"] = "mfa_setup";
|
|
953
|
+
FlowStep2["MFA_VERIFY"] = "mfa_verify";
|
|
954
|
+
FlowStep2["MFA_SELECT_METHOD"] = "mfa_select_method";
|
|
955
|
+
FlowStep2["EMAIL_VERIFICATION_REQUIRED"] = "email_verification_required";
|
|
956
|
+
FlowStep2["EMAIL_VERIFICATION_SENT"] = "email_verification_sent";
|
|
957
|
+
FlowStep2["PHONE_VERIFICATION_REQUIRED"] = "phone_verification_required";
|
|
958
|
+
FlowStep2["PASSWORD_RESET_REQUEST"] = "password_reset_request";
|
|
959
|
+
FlowStep2["PASSWORD_RESET_SENT"] = "password_reset_sent";
|
|
960
|
+
FlowStep2["PASSWORD_RESET_CONFIRM"] = "password_reset_confirm";
|
|
961
|
+
FlowStep2["PASSWORD_CHANGE"] = "password_change";
|
|
962
|
+
FlowStep2["PROFILE_UPDATE"] = "profile_update";
|
|
963
|
+
FlowStep2["PROFILE_COMPLETE"] = "profile_complete";
|
|
964
|
+
FlowStep2["SUCCESS"] = "success";
|
|
965
|
+
FlowStep2["ERROR"] = "error";
|
|
966
|
+
FlowStep2["CANCELLED"] = "cancelled";
|
|
967
|
+
return FlowStep2;
|
|
968
|
+
})(FlowStep || {});
|
|
969
|
+
var FlowConfigType = /* @__PURE__ */ ((FlowConfigType2) => {
|
|
970
|
+
FlowConfigType2["SIMPLE_SIGN_IN"] = "simple_sign_in";
|
|
971
|
+
FlowConfigType2["SIMPLE_SIGN_UP"] = "simple_sign_up";
|
|
972
|
+
FlowConfigType2["SIGN_UP_WITH_EMAIL_VERIFICATION"] = "sign_up_with_email_verification";
|
|
973
|
+
FlowConfigType2["SIGN_IN_WITH_MFA"] = "sign_in_with_mfa";
|
|
974
|
+
FlowConfigType2["OAUTH_SIGN_IN"] = "oauth_sign_in";
|
|
975
|
+
FlowConfigType2["MAGIC_LINK_FLOW"] = "magic_link_flow";
|
|
976
|
+
FlowConfigType2["PHONE_AUTH_FLOW"] = "phone_auth_flow";
|
|
977
|
+
FlowConfigType2["COMPLETE_SIGN_UP_FLOW"] = "complete_sign_up_flow";
|
|
978
|
+
FlowConfigType2["SECURE_SIGN_IN_FLOW"] = "secure_sign_in_flow";
|
|
979
|
+
FlowConfigType2["PASSWORD_RESET_FLOW"] = "password_reset_flow";
|
|
980
|
+
FlowConfigType2["CUSTOM"] = "custom";
|
|
981
|
+
return FlowConfigType2;
|
|
982
|
+
})(FlowConfigType || {});
|
|
983
|
+
var FlowAction = /* @__PURE__ */ ((FlowAction2) => {
|
|
984
|
+
FlowAction2["START"] = "start";
|
|
985
|
+
FlowAction2["NEXT"] = "next";
|
|
986
|
+
FlowAction2["BACK"] = "back";
|
|
987
|
+
FlowAction2["CANCEL"] = "cancel";
|
|
988
|
+
FlowAction2["ERROR"] = "error";
|
|
989
|
+
FlowAction2["RESET"] = "reset";
|
|
990
|
+
return FlowAction2;
|
|
991
|
+
})(FlowAction || {});
|
|
992
|
+
|
|
993
|
+
// src/flows/engine.ts
|
|
994
|
+
var FlowEngine = class {
|
|
995
|
+
constructor(config, initialState) {
|
|
996
|
+
this.history = [];
|
|
997
|
+
this.config = config;
|
|
998
|
+
this.state = {
|
|
999
|
+
currentStep: config.initialStep,
|
|
1000
|
+
...initialState
|
|
1001
|
+
};
|
|
1002
|
+
this.history.push(this.state.currentStep);
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Get current flow state
|
|
1006
|
+
*/
|
|
1007
|
+
getState() {
|
|
1008
|
+
return { ...this.state };
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Get current step
|
|
1012
|
+
*/
|
|
1013
|
+
getCurrentStep() {
|
|
1014
|
+
return this.state.currentStep;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Check if step is allowed in this flow
|
|
1018
|
+
*/
|
|
1019
|
+
isStepAllowed(step) {
|
|
1020
|
+
return this.config.allowedSteps.includes(step);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Transition to next step based on action
|
|
1024
|
+
*/
|
|
1025
|
+
async transition(event) {
|
|
1026
|
+
const { action, data, error } = event;
|
|
1027
|
+
switch (action) {
|
|
1028
|
+
case "start":
|
|
1029
|
+
return this.handleStart(data);
|
|
1030
|
+
case "next":
|
|
1031
|
+
return this.handleNext(data);
|
|
1032
|
+
case "back":
|
|
1033
|
+
return this.handleBack();
|
|
1034
|
+
case "cancel":
|
|
1035
|
+
return this.handleCancel();
|
|
1036
|
+
case "error":
|
|
1037
|
+
return this.handleError(error);
|
|
1038
|
+
case "reset":
|
|
1039
|
+
return this.handleReset();
|
|
1040
|
+
default:
|
|
1041
|
+
throw new AuthError(
|
|
1042
|
+
`Unknown flow action: ${action}`,
|
|
1043
|
+
"validation_error" /* VALIDATION_ERROR */
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Start or restart the flow
|
|
1049
|
+
*/
|
|
1050
|
+
handleStart(data) {
|
|
1051
|
+
this.state = {
|
|
1052
|
+
currentStep: this.config.initialStep,
|
|
1053
|
+
...data
|
|
1054
|
+
};
|
|
1055
|
+
this.history = [this.state.currentStep];
|
|
1056
|
+
if (this.config.onStepChange) {
|
|
1057
|
+
this.config.onStepChange(this.state.currentStep, this.state);
|
|
1058
|
+
}
|
|
1059
|
+
return this.getState();
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Move to next step
|
|
1063
|
+
*/
|
|
1064
|
+
handleNext(data) {
|
|
1065
|
+
this.state = {
|
|
1066
|
+
...this.state,
|
|
1067
|
+
...data,
|
|
1068
|
+
previousStep: this.state.currentStep
|
|
1069
|
+
};
|
|
1070
|
+
const transitionConfig = this.config.transitions[this.state.currentStep];
|
|
1071
|
+
if (!transitionConfig) {
|
|
1072
|
+
throw new AuthError(
|
|
1073
|
+
`No transition configured for step: ${this.state.currentStep}`,
|
|
1074
|
+
"validation_error" /* VALIDATION_ERROR */
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
if (transitionConfig.conditions) {
|
|
1078
|
+
for (const condition of transitionConfig.conditions) {
|
|
1079
|
+
if (condition.when(this.state)) {
|
|
1080
|
+
return this.moveToStep(condition.then);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
if (transitionConfig.onSuccess) {
|
|
1085
|
+
return this.moveToStep(transitionConfig.onSuccess);
|
|
1086
|
+
}
|
|
1087
|
+
throw new AuthError(
|
|
1088
|
+
`No valid transition found for step: ${this.state.currentStep}`,
|
|
1089
|
+
"validation_error" /* VALIDATION_ERROR */
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Go back to previous step
|
|
1094
|
+
*/
|
|
1095
|
+
handleBack() {
|
|
1096
|
+
if (this.history.length < 2) {
|
|
1097
|
+
throw new AuthError(
|
|
1098
|
+
"Cannot go back - already at first step",
|
|
1099
|
+
"validation_error" /* VALIDATION_ERROR */
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
this.history.pop();
|
|
1103
|
+
const previousStep = this.history[this.history.length - 1];
|
|
1104
|
+
const transitionConfig = this.config.transitions[this.state.currentStep];
|
|
1105
|
+
const targetStep = transitionConfig?.onBack || previousStep;
|
|
1106
|
+
return this.moveToStep(targetStep, false);
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Cancel the flow
|
|
1110
|
+
*/
|
|
1111
|
+
handleCancel() {
|
|
1112
|
+
const transitionConfig = this.config.transitions[this.state.currentStep];
|
|
1113
|
+
const targetStep = transitionConfig?.onCancel;
|
|
1114
|
+
if (this.config.onCancel) {
|
|
1115
|
+
this.config.onCancel(this.state);
|
|
1116
|
+
}
|
|
1117
|
+
if (targetStep) {
|
|
1118
|
+
return this.moveToStep(targetStep);
|
|
1119
|
+
}
|
|
1120
|
+
this.state.currentStep = "cancelled";
|
|
1121
|
+
return this.getState();
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Handle error in flow
|
|
1125
|
+
*/
|
|
1126
|
+
handleError(error) {
|
|
1127
|
+
this.state.error = error;
|
|
1128
|
+
const transitionConfig = this.config.transitions[this.state.currentStep];
|
|
1129
|
+
const targetStep = transitionConfig?.onError;
|
|
1130
|
+
if (this.config.onError) {
|
|
1131
|
+
this.config.onError(error, this.state);
|
|
1132
|
+
}
|
|
1133
|
+
if (targetStep) {
|
|
1134
|
+
return this.moveToStep(targetStep);
|
|
1135
|
+
}
|
|
1136
|
+
return this.getState();
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Reset flow to initial state
|
|
1140
|
+
*/
|
|
1141
|
+
handleReset() {
|
|
1142
|
+
return this.handleStart();
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Move to a specific step
|
|
1146
|
+
*/
|
|
1147
|
+
moveToStep(step, addToHistory = true) {
|
|
1148
|
+
if (!this.isStepAllowed(step)) {
|
|
1149
|
+
throw new AuthError(
|
|
1150
|
+
`Step ${step} is not allowed in this flow`,
|
|
1151
|
+
"validation_error" /* VALIDATION_ERROR */
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
this.state.currentStep = step;
|
|
1155
|
+
if (addToHistory) {
|
|
1156
|
+
this.history.push(step);
|
|
1157
|
+
}
|
|
1158
|
+
if (this.config.onStepChange) {
|
|
1159
|
+
this.config.onStepChange(step, this.state);
|
|
1160
|
+
}
|
|
1161
|
+
if (step === "success" && this.state.user && this.state.session) {
|
|
1162
|
+
if (this.config.onComplete) {
|
|
1163
|
+
this.config.onComplete(this.state.user, this.state.session);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
return this.getState();
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Get flow history
|
|
1170
|
+
*/
|
|
1171
|
+
getHistory() {
|
|
1172
|
+
return [...this.history];
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Check if can go back
|
|
1176
|
+
*/
|
|
1177
|
+
canGoBack() {
|
|
1178
|
+
return this.history.length > 1;
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
// src/flows/configs.ts
|
|
1183
|
+
var simpleSignInFlow = {
|
|
1184
|
+
name: "Simple Sign In",
|
|
1185
|
+
description: "Basic email/password sign-in",
|
|
1186
|
+
initialStep: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
|
|
1187
|
+
allowedSteps: [
|
|
1188
|
+
"email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
|
|
1189
|
+
"password_reset_request" /* PASSWORD_RESET_REQUEST */,
|
|
1190
|
+
"password_reset_sent" /* PASSWORD_RESET_SENT */,
|
|
1191
|
+
"success" /* SUCCESS */,
|
|
1192
|
+
"error" /* ERROR */
|
|
1193
|
+
],
|
|
1194
|
+
transitions: {
|
|
1195
|
+
["email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */]: {
|
|
1196
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1197
|
+
onError: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
|
|
1198
|
+
},
|
|
1199
|
+
["password_reset_request" /* PASSWORD_RESET_REQUEST */]: {
|
|
1200
|
+
onSuccess: "password_reset_sent" /* PASSWORD_RESET_SENT */,
|
|
1201
|
+
onBack: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
|
|
1202
|
+
},
|
|
1203
|
+
["password_reset_sent" /* PASSWORD_RESET_SENT */]: {
|
|
1204
|
+
onSuccess: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
var signInWithMFAFlow = {
|
|
1209
|
+
name: "Sign In with MFA",
|
|
1210
|
+
description: "Sign-in that handles MFA if enabled",
|
|
1211
|
+
initialStep: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
|
|
1212
|
+
allowedSteps: [
|
|
1213
|
+
"email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
|
|
1214
|
+
"mfa_required" /* MFA_REQUIRED */,
|
|
1215
|
+
"mfa_select_method" /* MFA_SELECT_METHOD */,
|
|
1216
|
+
"mfa_verify" /* MFA_VERIFY */,
|
|
1217
|
+
"password_reset_request" /* PASSWORD_RESET_REQUEST */,
|
|
1218
|
+
"password_reset_sent" /* PASSWORD_RESET_SENT */,
|
|
1219
|
+
"success" /* SUCCESS */,
|
|
1220
|
+
"error" /* ERROR */
|
|
1221
|
+
],
|
|
1222
|
+
transitions: {
|
|
1223
|
+
["email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */]: {
|
|
1224
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1225
|
+
onError: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
|
|
1226
|
+
conditions: [
|
|
1227
|
+
{
|
|
1228
|
+
when: (state) => state.mfaRequired === true,
|
|
1229
|
+
then: "mfa_required" /* MFA_REQUIRED */
|
|
1230
|
+
}
|
|
1231
|
+
]
|
|
1232
|
+
},
|
|
1233
|
+
["mfa_required" /* MFA_REQUIRED */]: {
|
|
1234
|
+
onSuccess: "mfa_verify" /* MFA_VERIFY */,
|
|
1235
|
+
conditions: [
|
|
1236
|
+
{
|
|
1237
|
+
when: (state) => (state.mfaMethods?.length || 0) > 1,
|
|
1238
|
+
then: "mfa_select_method" /* MFA_SELECT_METHOD */
|
|
1239
|
+
}
|
|
1240
|
+
]
|
|
1241
|
+
},
|
|
1242
|
+
["mfa_select_method" /* MFA_SELECT_METHOD */]: {
|
|
1243
|
+
onSuccess: "mfa_verify" /* MFA_VERIFY */,
|
|
1244
|
+
onBack: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
|
|
1245
|
+
},
|
|
1246
|
+
["mfa_verify" /* MFA_VERIFY */]: {
|
|
1247
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1248
|
+
onError: "mfa_verify" /* MFA_VERIFY */,
|
|
1249
|
+
onBack: "mfa_select_method" /* MFA_SELECT_METHOD */
|
|
1250
|
+
},
|
|
1251
|
+
["password_reset_request" /* PASSWORD_RESET_REQUEST */]: {
|
|
1252
|
+
onSuccess: "password_reset_sent" /* PASSWORD_RESET_SENT */,
|
|
1253
|
+
onBack: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
var completeSignUpFlow = {
|
|
1258
|
+
name: "Complete Sign Up",
|
|
1259
|
+
description: "Sign-up with email verification and profile completion",
|
|
1260
|
+
initialStep: "email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */,
|
|
1261
|
+
allowedSteps: [
|
|
1262
|
+
"email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */,
|
|
1263
|
+
"email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */,
|
|
1264
|
+
"email_verification_sent" /* EMAIL_VERIFICATION_SENT */,
|
|
1265
|
+
"profile_complete" /* PROFILE_COMPLETE */,
|
|
1266
|
+
"success" /* SUCCESS */,
|
|
1267
|
+
"error" /* ERROR */
|
|
1268
|
+
],
|
|
1269
|
+
transitions: {
|
|
1270
|
+
["email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */]: {
|
|
1271
|
+
onSuccess: "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */,
|
|
1272
|
+
onError: "email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */,
|
|
1273
|
+
conditions: [
|
|
1274
|
+
{
|
|
1275
|
+
when: (state) => state.verificationRequired === false,
|
|
1276
|
+
then: "profile_complete" /* PROFILE_COMPLETE */
|
|
1277
|
+
}
|
|
1278
|
+
]
|
|
1279
|
+
},
|
|
1280
|
+
["email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */]: {
|
|
1281
|
+
onSuccess: "email_verification_sent" /* EMAIL_VERIFICATION_SENT */
|
|
1282
|
+
},
|
|
1283
|
+
["email_verification_sent" /* EMAIL_VERIFICATION_SENT */]: {
|
|
1284
|
+
onSuccess: "profile_complete" /* PROFILE_COMPLETE */
|
|
1285
|
+
},
|
|
1286
|
+
["profile_complete" /* PROFILE_COMPLETE */]: {
|
|
1287
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1288
|
+
onError: "profile_complete" /* PROFILE_COMPLETE */
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
var magicLinkFlow = {
|
|
1293
|
+
name: "Magic Link",
|
|
1294
|
+
description: "Passwordless authentication via email",
|
|
1295
|
+
initialStep: "magic_link_request" /* MAGIC_LINK_REQUEST */,
|
|
1296
|
+
allowedSteps: [
|
|
1297
|
+
"magic_link_request" /* MAGIC_LINK_REQUEST */,
|
|
1298
|
+
"magic_link_sent" /* MAGIC_LINK_SENT */,
|
|
1299
|
+
"magic_link_verify" /* MAGIC_LINK_VERIFY */,
|
|
1300
|
+
"success" /* SUCCESS */,
|
|
1301
|
+
"error" /* ERROR */
|
|
1302
|
+
],
|
|
1303
|
+
transitions: {
|
|
1304
|
+
["magic_link_request" /* MAGIC_LINK_REQUEST */]: {
|
|
1305
|
+
onSuccess: "magic_link_sent" /* MAGIC_LINK_SENT */,
|
|
1306
|
+
onError: "magic_link_request" /* MAGIC_LINK_REQUEST */
|
|
1307
|
+
},
|
|
1308
|
+
["magic_link_sent" /* MAGIC_LINK_SENT */]: {
|
|
1309
|
+
onSuccess: "magic_link_verify" /* MAGIC_LINK_VERIFY */
|
|
1310
|
+
},
|
|
1311
|
+
["magic_link_verify" /* MAGIC_LINK_VERIFY */]: {
|
|
1312
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1313
|
+
onError: "magic_link_request" /* MAGIC_LINK_REQUEST */
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
var phoneAuthFlow = {
|
|
1318
|
+
name: "Phone Authentication",
|
|
1319
|
+
description: "SMS-based authentication",
|
|
1320
|
+
initialStep: "phone_request" /* PHONE_REQUEST */,
|
|
1321
|
+
allowedSteps: [
|
|
1322
|
+
"phone_request" /* PHONE_REQUEST */,
|
|
1323
|
+
"phone_verify" /* PHONE_VERIFY */,
|
|
1324
|
+
"success" /* SUCCESS */,
|
|
1325
|
+
"error" /* ERROR */
|
|
1326
|
+
],
|
|
1327
|
+
transitions: {
|
|
1328
|
+
["phone_request" /* PHONE_REQUEST */]: {
|
|
1329
|
+
onSuccess: "phone_verify" /* PHONE_VERIFY */,
|
|
1330
|
+
onError: "phone_request" /* PHONE_REQUEST */
|
|
1331
|
+
},
|
|
1332
|
+
["phone_verify" /* PHONE_VERIFY */]: {
|
|
1333
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1334
|
+
onError: "phone_verify" /* PHONE_VERIFY */,
|
|
1335
|
+
onBack: "phone_request" /* PHONE_REQUEST */
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
var oauthSignInFlow = {
|
|
1340
|
+
name: "OAuth Sign In",
|
|
1341
|
+
description: "Third-party OAuth authentication",
|
|
1342
|
+
initialStep: "oauth_select" /* OAUTH_SELECT */,
|
|
1343
|
+
allowedSteps: [
|
|
1344
|
+
"oauth_select" /* OAUTH_SELECT */,
|
|
1345
|
+
"oauth_callback" /* OAUTH_CALLBACK */,
|
|
1346
|
+
"success" /* SUCCESS */,
|
|
1347
|
+
"error" /* ERROR */
|
|
1348
|
+
],
|
|
1349
|
+
transitions: {
|
|
1350
|
+
["oauth_select" /* OAUTH_SELECT */]: {
|
|
1351
|
+
onSuccess: "oauth_callback" /* OAUTH_CALLBACK */,
|
|
1352
|
+
onError: "oauth_select" /* OAUTH_SELECT */
|
|
1353
|
+
},
|
|
1354
|
+
["oauth_callback" /* OAUTH_CALLBACK */]: {
|
|
1355
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1356
|
+
onError: "oauth_select" /* OAUTH_SELECT */
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
var passwordResetFlow = {
|
|
1361
|
+
name: "Password Reset",
|
|
1362
|
+
description: "Reset forgotten password",
|
|
1363
|
+
initialStep: "password_reset_request" /* PASSWORD_RESET_REQUEST */,
|
|
1364
|
+
allowedSteps: [
|
|
1365
|
+
"password_reset_request" /* PASSWORD_RESET_REQUEST */,
|
|
1366
|
+
"password_reset_sent" /* PASSWORD_RESET_SENT */,
|
|
1367
|
+
"password_reset_confirm" /* PASSWORD_RESET_CONFIRM */,
|
|
1368
|
+
"success" /* SUCCESS */,
|
|
1369
|
+
"error" /* ERROR */
|
|
1370
|
+
],
|
|
1371
|
+
transitions: {
|
|
1372
|
+
["password_reset_request" /* PASSWORD_RESET_REQUEST */]: {
|
|
1373
|
+
onSuccess: "password_reset_sent" /* PASSWORD_RESET_SENT */,
|
|
1374
|
+
onError: "password_reset_request" /* PASSWORD_RESET_REQUEST */
|
|
1375
|
+
},
|
|
1376
|
+
["password_reset_sent" /* PASSWORD_RESET_SENT */]: {
|
|
1377
|
+
onSuccess: "password_reset_confirm" /* PASSWORD_RESET_CONFIRM */
|
|
1378
|
+
},
|
|
1379
|
+
["password_reset_confirm" /* PASSWORD_RESET_CONFIRM */]: {
|
|
1380
|
+
onSuccess: "success" /* SUCCESS */,
|
|
1381
|
+
onError: "password_reset_confirm" /* PASSWORD_RESET_CONFIRM */
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
function getFlowConfig(type) {
|
|
1386
|
+
switch (type) {
|
|
1387
|
+
case "simple_sign_in" /* SIMPLE_SIGN_IN */:
|
|
1388
|
+
return simpleSignInFlow;
|
|
1389
|
+
case "sign_in_with_mfa" /* SIGN_IN_WITH_MFA */:
|
|
1390
|
+
return signInWithMFAFlow;
|
|
1391
|
+
case "complete_sign_up_flow" /* COMPLETE_SIGN_UP_FLOW */:
|
|
1392
|
+
return completeSignUpFlow;
|
|
1393
|
+
case "magic_link_flow" /* MAGIC_LINK_FLOW */:
|
|
1394
|
+
return magicLinkFlow;
|
|
1395
|
+
case "phone_auth_flow" /* PHONE_AUTH_FLOW */:
|
|
1396
|
+
return phoneAuthFlow;
|
|
1397
|
+
case "oauth_sign_in" /* OAUTH_SIGN_IN */:
|
|
1398
|
+
return oauthSignInFlow;
|
|
1399
|
+
case "password_reset_flow" /* PASSWORD_RESET_FLOW */:
|
|
1400
|
+
return passwordResetFlow;
|
|
1401
|
+
default:
|
|
1402
|
+
throw new Error(`Unknown flow type: ${type}`);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
var predefinedFlows = {
|
|
1406
|
+
["simple_sign_in" /* SIMPLE_SIGN_IN */]: simpleSignInFlow,
|
|
1407
|
+
["sign_in_with_mfa" /* SIGN_IN_WITH_MFA */]: signInWithMFAFlow,
|
|
1408
|
+
["complete_sign_up_flow" /* COMPLETE_SIGN_UP_FLOW */]: completeSignUpFlow,
|
|
1409
|
+
["magic_link_flow" /* MAGIC_LINK_FLOW */]: magicLinkFlow,
|
|
1410
|
+
["phone_auth_flow" /* PHONE_AUTH_FLOW */]: phoneAuthFlow,
|
|
1411
|
+
["oauth_sign_in" /* OAUTH_SIGN_IN */]: oauthSignInFlow,
|
|
1412
|
+
["password_reset_flow" /* PASSWORD_RESET_FLOW */]: passwordResetFlow
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1415
|
+
exports.AuthClient = AuthClient;
|
|
1416
|
+
exports.AuthError = AuthError;
|
|
1417
|
+
exports.AuthErrorType = AuthErrorType;
|
|
1418
|
+
exports.AuthState = AuthState;
|
|
1419
|
+
exports.BaseAuthProvider = BaseAuthProvider;
|
|
1420
|
+
exports.FlowAction = FlowAction;
|
|
1421
|
+
exports.FlowConfigType = FlowConfigType;
|
|
1422
|
+
exports.FlowEngine = FlowEngine;
|
|
1423
|
+
exports.FlowStep = FlowStep;
|
|
1424
|
+
exports.LocalStorageAdapter = LocalStorageAdapter;
|
|
1425
|
+
exports.MemoryStorageAdapter = MemoryStorageAdapter;
|
|
1426
|
+
exports.OAuthProvider = OAuthProvider;
|
|
1427
|
+
exports.Observable = Observable;
|
|
1428
|
+
exports.SessionStorageAdapter = SessionStorageAdapter;
|
|
1429
|
+
exports.TokenManager = TokenManager;
|
|
1430
|
+
exports.TwoFactorMethod = TwoFactorMethod;
|
|
1431
|
+
exports.completeSignUpFlow = completeSignUpFlow;
|
|
1432
|
+
exports.createAuthError = createAuthError;
|
|
1433
|
+
exports.getFlowConfig = getFlowConfig;
|
|
1434
|
+
exports.isAuthError = isAuthError;
|
|
1435
|
+
exports.isMFARequiredError = isMFARequiredError;
|
|
1436
|
+
exports.isNetworkError = isNetworkError;
|
|
1437
|
+
exports.isUnauthenticatedError = isUnauthenticatedError;
|
|
1438
|
+
exports.magicLinkFlow = magicLinkFlow;
|
|
1439
|
+
exports.oauthSignInFlow = oauthSignInFlow;
|
|
1440
|
+
exports.passwordResetFlow = passwordResetFlow;
|
|
1441
|
+
exports.phoneAuthFlow = phoneAuthFlow;
|
|
1442
|
+
exports.predefinedFlows = predefinedFlows;
|
|
1443
|
+
exports.signInWithMFAFlow = signInWithMFAFlow;
|
|
1444
|
+
exports.simpleSignInFlow = simpleSignInFlow;
|
|
1445
|
+
exports.toAuthError = toAuthError;
|
|
1446
|
+
exports.validate2FACode = validate2FACode;
|
|
1447
|
+
exports.validateEmail = validateEmail;
|
|
1448
|
+
exports.validatePassword = validatePassword;
|
|
1449
|
+
exports.validatePhone = validatePhone;
|
|
1450
|
+
exports.validateRequired = validateRequired;
|
|
1451
|
+
exports.validateUsername = validateUsername;
|
|
1452
|
+
//# sourceMappingURL=index.js.map
|
|
1453
|
+
//# sourceMappingURL=index.js.map
|