@passflow/core 0.21.1 → 0.23.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 +88 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -5
- package/dist/index.d.ts +157 -5
- package/dist/index.mjs +738 -658
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
- [Federated Authentication](#federated-authentication)
|
|
34
34
|
- [Passkey Authentication](#passkey-authentication)
|
|
35
35
|
- [Password Reset](#password-reset)
|
|
36
|
+
- [Email verification](#email-verification)
|
|
36
37
|
- [Token Management](#token-management)
|
|
37
38
|
- [Tenant Management](#tenant-management)
|
|
38
39
|
- [Invitation Management](#invitation-management)
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
- [PassflowSignUpPayload](#passflowsignuppayload)
|
|
52
53
|
- [UserMembership](#usermembership)
|
|
53
54
|
- [PassflowEvent](#passflowevent)
|
|
55
|
+
- [Admin settings secrets](#admin-settings-secrets)
|
|
54
56
|
- [Detailed Examples](#detailed-examples)
|
|
55
57
|
- [Complete Sign In Flow](#complete-sign-in-flow)
|
|
56
58
|
- [Authentication with Passkeys](#authentication-with-passkeys)
|
|
@@ -463,7 +465,8 @@ const sendResetEmail = async () => {
|
|
|
463
465
|
// Reset password (after receiving reset token)
|
|
464
466
|
const resetPassword = async (newPassword) => {
|
|
465
467
|
try {
|
|
466
|
-
// The token
|
|
468
|
+
// The token is read from the URL query, or from the query of a hash route
|
|
469
|
+
// (#/reset?token=...). Pass it as the third argument when it lives elsewhere.
|
|
467
470
|
const response = await passflow.resetPassword(newPassword);
|
|
468
471
|
console.log("Password reset successful", response);
|
|
469
472
|
} catch (error) {
|
|
@@ -472,6 +475,59 @@ const resetPassword = async (newPassword) => {
|
|
|
472
475
|
};
|
|
473
476
|
```
|
|
474
477
|
|
|
478
|
+
### Email verification
|
|
479
|
+
|
|
480
|
+
When the server needs the user's email proven first, `signIn`, `signUp` and `resetPassword` answer
|
|
481
|
+
with an email verification step instead of a session. They do not throw: the step comes back as the
|
|
482
|
+
response, no tokens are stored, and the SDK emits `PassflowEvent.EmailVerificationRequired`.
|
|
483
|
+
|
|
484
|
+
```typescript
|
|
485
|
+
type PassflowEmailVerificationStep = {
|
|
486
|
+
email_verification_required: true;
|
|
487
|
+
message: string; // e.g. "We sent a code to a***@example.com."
|
|
488
|
+
challenge_id?: string; // present when a code was emailed
|
|
489
|
+
};
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Check the answer with `isEmailVerificationStep`. With a `challenge_id`, ask the user for the code
|
|
493
|
+
from the email and finish with `verifyEmailCode({ challenge_id, otp })`:
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
import { isEmailVerificationStep } from "@passflow/core";
|
|
497
|
+
|
|
498
|
+
const response = await passflow.signUp({
|
|
499
|
+
user: { email: "user@example.com", password: "password123" },
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
if (isEmailVerificationStep(response)) {
|
|
503
|
+
showMessage(response.message);
|
|
504
|
+
if (response.challenge_id) {
|
|
505
|
+
const otp = await askUserForCode();
|
|
506
|
+
const session = await passflow.verifyEmailCode({
|
|
507
|
+
challenge_id: response.challenge_id,
|
|
508
|
+
otp,
|
|
509
|
+
});
|
|
510
|
+
// session holds a new token pair, or a tfa_token when a second factor is owed
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
`verifyEmailCode` answers like `signIn`: a new token pair, or a `tfa_token` when a second factor is
|
|
516
|
+
owed (`isTwoFactorVerificationRequired()` is then true and `TwoFactorRequired` is emitted). A wrong,
|
|
517
|
+
expired or spent code throws a `PassflowError` with an `error.otp.*` id, and an unknown challenge
|
|
518
|
+
throws `error.not.found`. To send a fresh code, call the original method again; the new step has a
|
|
519
|
+
new `challenge_id`.
|
|
520
|
+
|
|
521
|
+
- **Register or SignIn.** `verifyEmailCode` emits `Register` for a challenge this `Passflow`
|
|
522
|
+
instance got from `signUp`, and `SignIn` for one from `signIn` or `resetPassword`. Challenges are
|
|
523
|
+
remembered in memory only, so a code entered in another tab, after a reload, or on a recreated
|
|
524
|
+
instance emits `SignIn`, even for a sign-up. It emits no `SignInStart` or `RegisterStart`.
|
|
525
|
+
- **No `challenge_id`.** The code budget is spent and the server emailed a link instead. There is
|
|
526
|
+
nothing to call: show `message` and let the user follow the link.
|
|
527
|
+
- **Password reset.** `resetPassword(newPassword, scopes?, resetToken?)` takes the reset token as
|
|
528
|
+
an optional third argument. Without it, the SDK reads `token` from the URL query, then from the
|
|
529
|
+
query of a hash route (`#/reset?token=...`).
|
|
530
|
+
|
|
475
531
|
## Token Management
|
|
476
532
|
|
|
477
533
|
```javascript
|
|
@@ -658,6 +714,12 @@ const subscriber = {
|
|
|
658
714
|
case "refresh":
|
|
659
715
|
// Handle token refresh
|
|
660
716
|
break;
|
|
717
|
+
case "email-verification:required":
|
|
718
|
+
// signIn, signUp or resetPassword is waiting for the email to be proven.
|
|
719
|
+
// source: { email?, challengeId?, operation: "sign-up" | "sign-in" | "reset-password" }
|
|
720
|
+
// challengeId is set when a code was emailed (finish with verifyEmailCode),
|
|
721
|
+
// and absent when a link was emailed instead. email is set when the SDK knows it.
|
|
722
|
+
break;
|
|
661
723
|
}
|
|
662
724
|
},
|
|
663
725
|
};
|
|
@@ -736,7 +798,8 @@ Configuration options:
|
|
|
736
798
|
| `passkeyRegister(payload)` | Register a new passkey |
|
|
737
799
|
| `passkeyAuthenticate(payload)` | Authenticate with a passkey |
|
|
738
800
|
| `sendPasswordResetEmail(payload)` | Send password reset email |
|
|
739
|
-
| `resetPassword(newPassword, scopes)`
|
|
801
|
+
| `resetPassword(newPassword, scopes?, resetToken?)` | Reset password |
|
|
802
|
+
| `verifyEmailCode({ challenge_id, otp })` | Finish an email verification step |
|
|
740
803
|
|
|
741
804
|
**Token Methods**
|
|
742
805
|
|
|
@@ -889,10 +952,33 @@ enum PassflowEvent {
|
|
|
889
952
|
RefreshRecovered = "refresh:recovered",
|
|
890
953
|
SessionExpired = "session:expired",
|
|
891
954
|
TokenCacheExpired = "token-cache-expired",
|
|
955
|
+
EmailVerificationRequired = "email-verification:required",
|
|
892
956
|
// ...and the sign-in, 2FA and session events; see lib/store.ts
|
|
893
957
|
}
|
|
894
958
|
```
|
|
895
959
|
|
|
960
|
+
#### Admin settings secrets
|
|
961
|
+
|
|
962
|
+
App secrets are write-only and server settings secrets come back masked. The SDK has no admin
|
|
963
|
+
client; these exports are for admin UIs that call the admin routes themselves.
|
|
964
|
+
|
|
965
|
+
```typescript
|
|
966
|
+
type AppSettings = {
|
|
967
|
+
// ...
|
|
968
|
+
debug_otp_code_for_registration?: string; // write-only: answers return ""
|
|
969
|
+
debug_otp_code_set?: boolean; // read-only: true when a code is stored
|
|
970
|
+
};
|
|
971
|
+
type AppSecretName = "debug_otp_code_for_registration" | "fcm_server_key" | "webpush_vapid_private_key";
|
|
972
|
+
const APP_SECRET_NAMES: readonly AppSecretName[]; // DELETE /admin/apps/{id}/secrets/{name}
|
|
973
|
+
|
|
974
|
+
type MaskedSecret = string; // "mask://********" or "mask://********/<16 hex>"
|
|
975
|
+
const MASKED_SECRET_PREFIX = "mask://";
|
|
976
|
+
const SETTINGS_MASKED_VALUE_UNKNOWN_ERROR_ID = "error.server.update.settings.masked.value.unknown";
|
|
977
|
+
function isMaskedSecret(value: unknown): value is MaskedSecret;
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
Write, keep and clear rules: [docs/admin-secrets.md](docs/admin-secrets.md).
|
|
981
|
+
|
|
896
982
|
## Detailed Examples
|
|
897
983
|
|
|
898
984
|
### Complete Sign In Flow
|