@absolutejs/auth 0.65.4 → 0.65.6
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 +62 -44
- package/dist/cli/migrate.js.map +5 -5
- 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 +79 -20
- package/dist/index.js.map +11 -11
- package/dist/server.js +79 -20
- package/dist/server.js.map +11 -11
- 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,
|
|
@@ -32527,7 +32568,7 @@ var createNeonLinkedProviderGrantStore = (db) => ({
|
|
|
32527
32568
|
owner_ref: grant.ownerRef,
|
|
32528
32569
|
provider_family: grant.providerFamily,
|
|
32529
32570
|
provider_subject: grant.providerSubject,
|
|
32530
|
-
refresh_token_ciphertext:
|
|
32571
|
+
refresh_token_ciphertext: sql`coalesce(excluded.refresh_token_ciphertext, ${linkedProviderGrantsTable.refresh_token_ciphertext})`,
|
|
32531
32572
|
status: grant.status,
|
|
32532
32573
|
token_type: grant.tokenType ?? null,
|
|
32533
32574
|
updated_at: new Date(grant.updatedAt)
|
|
@@ -32586,7 +32627,11 @@ var createInMemoryLinkedProviderStores = (input = {}) => {
|
|
|
32586
32627
|
[...bindings.entries()].filter(([, binding]) => binding.grantId === id).forEach(([bindingId2]) => bindings.delete(bindingId2));
|
|
32587
32628
|
},
|
|
32588
32629
|
saveGrant: async (grant) => {
|
|
32589
|
-
grants.
|
|
32630
|
+
const existing = grants.get(grant.id);
|
|
32631
|
+
grants.set(grant.id, cloneGrant({
|
|
32632
|
+
...grant,
|
|
32633
|
+
refreshTokenCiphertext: grant.refreshTokenCiphertext ?? existing?.refreshTokenCiphertext
|
|
32634
|
+
}));
|
|
32590
32635
|
}
|
|
32591
32636
|
};
|
|
32592
32637
|
const bindingStore = {
|
|
@@ -33006,7 +33051,8 @@ var validateEmailDeliverability = async (email, options) => {
|
|
|
33006
33051
|
};
|
|
33007
33052
|
// src/credentials/inMemoryCredentialStore.ts
|
|
33008
33053
|
var cloneCredential = (value) => ({
|
|
33009
|
-
...value
|
|
33054
|
+
...value,
|
|
33055
|
+
registrationData: value.registrationData === undefined ? undefined : structuredClone(value.registrationData)
|
|
33010
33056
|
});
|
|
33011
33057
|
var cloneToken = (value) => ({ ...value });
|
|
33012
33058
|
var consumeToken = (tokens, tokenHash) => {
|
|
@@ -33061,6 +33107,7 @@ var credentialsTable = pgTable("auth_credentials", {
|
|
|
33061
33107
|
email_verified: boolean("email_verified").notNull().default(false),
|
|
33062
33108
|
organization_id: varchar("organization_id", { length: ID_LENGTH2 }),
|
|
33063
33109
|
password_hash: text("password_hash").notNull(),
|
|
33110
|
+
registration_data: jsonb("registration_data").$type(),
|
|
33064
33111
|
status: varchar("status", { length: STATUS_LENGTH }).notNull().default("active"),
|
|
33065
33112
|
updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull(),
|
|
33066
33113
|
user_id: varchar("user_id", { length: ID_LENGTH2 })
|
|
@@ -33082,6 +33129,7 @@ var toCredentialRecord = (row) => ({
|
|
|
33082
33129
|
emailVerified: row.email_verified,
|
|
33083
33130
|
organizationId: row.organization_id ?? undefined,
|
|
33084
33131
|
passwordHash: row.password_hash,
|
|
33132
|
+
registrationData: row.registration_data ?? undefined,
|
|
33085
33133
|
status: isCredentialStatus(row.status) ? row.status : "active",
|
|
33086
33134
|
updatedAt: row.updated_at_ms,
|
|
33087
33135
|
userId: row.user_id ?? undefined
|
|
@@ -33123,6 +33171,7 @@ var createPostgresCredentialStore = (db) => ({
|
|
|
33123
33171
|
email_verified: credential.emailVerified,
|
|
33124
33172
|
organization_id: credential.organizationId ?? null,
|
|
33125
33173
|
password_hash: credential.passwordHash,
|
|
33174
|
+
registration_data: credential.registrationData ?? null,
|
|
33126
33175
|
status: credential.status,
|
|
33127
33176
|
updated_at_ms: credential.updatedAt,
|
|
33128
33177
|
user_id: credential.userId ?? null
|
|
@@ -37767,6 +37816,10 @@ var mfaSmsColumnsMigration = {
|
|
|
37767
37816
|
].join(`
|
|
37768
37817
|
`)
|
|
37769
37818
|
};
|
|
37819
|
+
var credentialDeferredUserMigration = {
|
|
37820
|
+
id: "0002_deferred_user_creation",
|
|
37821
|
+
sql: 'ALTER TABLE "auth_credentials" ADD COLUMN IF NOT EXISTS "registration_data" jsonb;'
|
|
37822
|
+
};
|
|
37770
37823
|
var mfaTotpLockoutMigration = {
|
|
37771
37824
|
id: "0003_totp_lockout",
|
|
37772
37825
|
sql: 'ALTER TABLE "auth_mfa_enrollments" ADD COLUMN IF NOT EXISTS "totp_failed_attempts" smallint NOT NULL DEFAULT 0;'
|
|
@@ -37822,11 +37875,17 @@ var blockMigrations = {
|
|
|
37822
37875
|
apiKeysTable
|
|
37823
37876
|
]),
|
|
37824
37877
|
audit: initMigration("audit", [auditEventsTable]),
|
|
37825
|
-
credentials:
|
|
37826
|
-
|
|
37827
|
-
|
|
37828
|
-
|
|
37829
|
-
|
|
37878
|
+
credentials: {
|
|
37879
|
+
block: "credentials",
|
|
37880
|
+
migrations: [
|
|
37881
|
+
...initMigration("credentials", [
|
|
37882
|
+
credentialsTable,
|
|
37883
|
+
credentialResetTokensTable,
|
|
37884
|
+
credentialVerificationTokensTable
|
|
37885
|
+
]).migrations,
|
|
37886
|
+
credentialDeferredUserMigration
|
|
37887
|
+
]
|
|
37888
|
+
},
|
|
37830
37889
|
fga: initMigration("fga", [warrantsTable]),
|
|
37831
37890
|
linkedProviders: initMigration("linkedProviders", [
|
|
37832
37891
|
linkedProviderBindingsTable,
|
|
@@ -38843,5 +38902,5 @@ export {
|
|
|
38843
38902
|
VerificationProviderError
|
|
38844
38903
|
};
|
|
38845
38904
|
|
|
38846
|
-
//# debugId=
|
|
38905
|
+
//# debugId=9E267BACCB0FD73264756E2164756E21
|
|
38847
38906
|
//# sourceMappingURL=server.js.map
|