@absolutejs/auth 0.65.4 → 0.65.5
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/cli/migrate.js +61 -43
- package/dist/cli/migrate.js.map +4 -4
- package/dist/credentials/config.d.ts +4 -3
- package/dist/credentials/emailVerification.d.ts +2 -14
- package/dist/credentials/postgresCredentialStore.d.ts +15 -0
- package/dist/credentials/routes.d.ts +1 -13
- package/dist/credentials/types.d.ts +6 -0
- package/dist/index.d.ts +1 -13
- package/dist/index.js +73 -18
- package/dist/index.js.map +9 -9
- package/dist/server.js +73 -18
- package/dist/server.js.map +9 -9
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -6120,8 +6120,12 @@ var DEFAULT_VERIFICATION_TOKEN_TTL_MS = MILLISECONDS_IN_A_DAY;
|
|
|
6120
6120
|
// src/credentials/emailVerification.ts
|
|
6121
6121
|
var credentialsEmailVerification = ({
|
|
6122
6122
|
credentialStore,
|
|
6123
|
+
getUserByEmail,
|
|
6124
|
+
onCreateCredentialUser,
|
|
6123
6125
|
onEmailVerified,
|
|
6126
|
+
onRegistrationSuccess,
|
|
6124
6127
|
onSendEmail,
|
|
6128
|
+
requireEmailVerification = false,
|
|
6125
6129
|
verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS,
|
|
6126
6130
|
verifyEmailRoute = "/auth/verify-email"
|
|
6127
6131
|
}) => new Elysia10().post(verifyEmailRoute, async ({ body: { token }, status }) => {
|
|
@@ -6132,7 +6136,36 @@ var credentialsEmailVerification = ({
|
|
|
6132
6136
|
if (consumed.expiresAt < Date.now()) {
|
|
6133
6137
|
return status("Bad Request", "Invalid or expired verification token");
|
|
6134
6138
|
}
|
|
6139
|
+
const credential = await credentialStore.getCredentialByEmail(consumed.email);
|
|
6140
|
+
if (!credential) {
|
|
6141
|
+
return status("Bad Request", "Invalid or expired verification token");
|
|
6142
|
+
}
|
|
6143
|
+
let user = await getUserByEmail(consumed.email);
|
|
6144
|
+
if (requireEmailVerification && !user && credential.registrationData !== undefined) {
|
|
6145
|
+
const created = await onCreateCredentialUser({
|
|
6146
|
+
...credential.registrationData,
|
|
6147
|
+
email: consumed.email
|
|
6148
|
+
});
|
|
6149
|
+
if (created instanceof Response || isStatusResponse(created)) {
|
|
6150
|
+
return created;
|
|
6151
|
+
}
|
|
6152
|
+
user = created;
|
|
6153
|
+
}
|
|
6135
6154
|
await credentialStore.setEmailVerified(consumed.email);
|
|
6155
|
+
if (credential.registrationData !== undefined) {
|
|
6156
|
+
await credentialStore.saveCredential({
|
|
6157
|
+
...credential,
|
|
6158
|
+
emailVerified: true,
|
|
6159
|
+
registrationData: undefined,
|
|
6160
|
+
updatedAt: Date.now()
|
|
6161
|
+
});
|
|
6162
|
+
}
|
|
6163
|
+
if (user && credential.registrationData !== undefined) {
|
|
6164
|
+
await onRegistrationSuccess?.({
|
|
6165
|
+
email: consumed.email,
|
|
6166
|
+
user
|
|
6167
|
+
});
|
|
6168
|
+
}
|
|
6136
6169
|
await onEmailVerified?.({ email: consumed.email });
|
|
6137
6170
|
return status("OK", { status: "email_verified" });
|
|
6138
6171
|
}, { body: t7.Object({ token: t7.String() }) }).post(`${verifyEmailRoute}/request`, async ({ body: { email }, status }) => {
|
|
@@ -6506,7 +6539,7 @@ var credentialsPasswordReset = ({
|
|
|
6506
6539
|
}) => new Elysia12().post(`${resetPasswordRoute}/request`, async ({ body: { email }, status }) => {
|
|
6507
6540
|
const normalizedEmail = email.trim().toLowerCase();
|
|
6508
6541
|
const credential = await credentialStore.getCredentialByEmail(normalizedEmail);
|
|
6509
|
-
if (credential && credential.status === "active") {
|
|
6542
|
+
if (credential && credential.status === "active" && credential.registrationData === undefined) {
|
|
6510
6543
|
const token = generateSecureToken();
|
|
6511
6544
|
const expiresAt = Date.now() + resetTokenDurationMs;
|
|
6512
6545
|
await credentialStore.saveResetToken({
|
|
@@ -6616,12 +6649,16 @@ var credentialsRegister = ({
|
|
|
6616
6649
|
status: "verification_required"
|
|
6617
6650
|
});
|
|
6618
6651
|
}
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6652
|
+
let created;
|
|
6653
|
+
if (!requireEmailVerification) {
|
|
6654
|
+
const result = await onCreateCredentialUser({
|
|
6655
|
+
...extraFields,
|
|
6656
|
+
email: normalizedEmail
|
|
6657
|
+
});
|
|
6658
|
+
if (result instanceof Response || isStatusResponse(result)) {
|
|
6659
|
+
return result;
|
|
6660
|
+
}
|
|
6661
|
+
created = result;
|
|
6625
6662
|
}
|
|
6626
6663
|
const now = Date.now();
|
|
6627
6664
|
await credentialStore.saveCredential({
|
|
@@ -6629,6 +6666,7 @@ var credentialsRegister = ({
|
|
|
6629
6666
|
email: normalizedEmail,
|
|
6630
6667
|
emailVerified: false,
|
|
6631
6668
|
passwordHash: await hashPassword(password),
|
|
6669
|
+
registrationData: requireEmailVerification ? extraFields : undefined,
|
|
6632
6670
|
status: "active",
|
|
6633
6671
|
updatedAt: now
|
|
6634
6672
|
});
|
|
@@ -6645,15 +6683,18 @@ var credentialsRegister = ({
|
|
|
6645
6683
|
token,
|
|
6646
6684
|
type: "verify_email"
|
|
6647
6685
|
});
|
|
6648
|
-
await onRegistrationSuccess?.({
|
|
6649
|
-
email: normalizedEmail,
|
|
6650
|
-
user: created
|
|
6651
|
-
});
|
|
6652
6686
|
if (requireEmailVerification) {
|
|
6653
6687
|
return status("Created", {
|
|
6654
6688
|
status: "verification_required"
|
|
6655
6689
|
});
|
|
6656
6690
|
}
|
|
6691
|
+
if (created === undefined) {
|
|
6692
|
+
throw new Error("Credential user was not created");
|
|
6693
|
+
}
|
|
6694
|
+
await onRegistrationSuccess?.({
|
|
6695
|
+
email: normalizedEmail,
|
|
6696
|
+
user: created
|
|
6697
|
+
});
|
|
6657
6698
|
const userSessionId = await promoteToSession({
|
|
6658
6699
|
authSessionStore,
|
|
6659
6700
|
cookie: user_session_id,
|
|
@@ -33006,7 +33047,8 @@ var validateEmailDeliverability = async (email, options) => {
|
|
|
33006
33047
|
};
|
|
33007
33048
|
// src/credentials/inMemoryCredentialStore.ts
|
|
33008
33049
|
var cloneCredential = (value) => ({
|
|
33009
|
-
...value
|
|
33050
|
+
...value,
|
|
33051
|
+
registrationData: value.registrationData === undefined ? undefined : structuredClone(value.registrationData)
|
|
33010
33052
|
});
|
|
33011
33053
|
var cloneToken = (value) => ({ ...value });
|
|
33012
33054
|
var consumeToken = (tokens, tokenHash) => {
|
|
@@ -33061,6 +33103,7 @@ var credentialsTable = pgTable("auth_credentials", {
|
|
|
33061
33103
|
email_verified: boolean("email_verified").notNull().default(false),
|
|
33062
33104
|
organization_id: varchar("organization_id", { length: ID_LENGTH2 }),
|
|
33063
33105
|
password_hash: text("password_hash").notNull(),
|
|
33106
|
+
registration_data: jsonb("registration_data").$type(),
|
|
33064
33107
|
status: varchar("status", { length: STATUS_LENGTH }).notNull().default("active"),
|
|
33065
33108
|
updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull(),
|
|
33066
33109
|
user_id: varchar("user_id", { length: ID_LENGTH2 })
|
|
@@ -33082,6 +33125,7 @@ var toCredentialRecord = (row) => ({
|
|
|
33082
33125
|
emailVerified: row.email_verified,
|
|
33083
33126
|
organizationId: row.organization_id ?? undefined,
|
|
33084
33127
|
passwordHash: row.password_hash,
|
|
33128
|
+
registrationData: row.registration_data ?? undefined,
|
|
33085
33129
|
status: isCredentialStatus(row.status) ? row.status : "active",
|
|
33086
33130
|
updatedAt: row.updated_at_ms,
|
|
33087
33131
|
userId: row.user_id ?? undefined
|
|
@@ -33123,6 +33167,7 @@ var createPostgresCredentialStore = (db) => ({
|
|
|
33123
33167
|
email_verified: credential.emailVerified,
|
|
33124
33168
|
organization_id: credential.organizationId ?? null,
|
|
33125
33169
|
password_hash: credential.passwordHash,
|
|
33170
|
+
registration_data: credential.registrationData ?? null,
|
|
33126
33171
|
status: credential.status,
|
|
33127
33172
|
updated_at_ms: credential.updatedAt,
|
|
33128
33173
|
user_id: credential.userId ?? null
|
|
@@ -37767,6 +37812,10 @@ var mfaSmsColumnsMigration = {
|
|
|
37767
37812
|
].join(`
|
|
37768
37813
|
`)
|
|
37769
37814
|
};
|
|
37815
|
+
var credentialDeferredUserMigration = {
|
|
37816
|
+
id: "0002_deferred_user_creation",
|
|
37817
|
+
sql: 'ALTER TABLE "auth_credentials" ADD COLUMN IF NOT EXISTS "registration_data" jsonb;'
|
|
37818
|
+
};
|
|
37770
37819
|
var mfaTotpLockoutMigration = {
|
|
37771
37820
|
id: "0003_totp_lockout",
|
|
37772
37821
|
sql: 'ALTER TABLE "auth_mfa_enrollments" ADD COLUMN IF NOT EXISTS "totp_failed_attempts" smallint NOT NULL DEFAULT 0;'
|
|
@@ -37822,11 +37871,17 @@ var blockMigrations = {
|
|
|
37822
37871
|
apiKeysTable
|
|
37823
37872
|
]),
|
|
37824
37873
|
audit: initMigration("audit", [auditEventsTable]),
|
|
37825
|
-
credentials:
|
|
37826
|
-
|
|
37827
|
-
|
|
37828
|
-
|
|
37829
|
-
|
|
37874
|
+
credentials: {
|
|
37875
|
+
block: "credentials",
|
|
37876
|
+
migrations: [
|
|
37877
|
+
...initMigration("credentials", [
|
|
37878
|
+
credentialsTable,
|
|
37879
|
+
credentialResetTokensTable,
|
|
37880
|
+
credentialVerificationTokensTable
|
|
37881
|
+
]).migrations,
|
|
37882
|
+
credentialDeferredUserMigration
|
|
37883
|
+
]
|
|
37884
|
+
},
|
|
37830
37885
|
fga: initMigration("fga", [warrantsTable]),
|
|
37831
37886
|
linkedProviders: initMigration("linkedProviders", [
|
|
37832
37887
|
linkedProviderBindingsTable,
|
|
@@ -38843,5 +38898,5 @@ export {
|
|
|
38843
38898
|
VerificationProviderError
|
|
38844
38899
|
};
|
|
38845
38900
|
|
|
38846
|
-
//# debugId=
|
|
38901
|
+
//# debugId=5901150ECA00DB6964756E2164756E21
|
|
38847
38902
|
//# sourceMappingURL=server.js.map
|