@absolutejs/auth 0.26.0-beta.0 → 0.26.0-beta.2

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.
@@ -23,7 +23,7 @@ export type CredentialsConfig<UserType> = {
23
23
  getUserByEmail: (email: string) => Promise<UserType | null | undefined> | UserType | null | undefined;
24
24
  isMfaRequired?: (user: UserType) => boolean | Promise<boolean>;
25
25
  loginRoute?: RouteString;
26
- onCreateCredentialUser: (identity: CredentialIdentity) => Promise<Response | StatusReturn | UserType> | Response | StatusReturn | UserType;
26
+ onCreateCredentialUser: (identity: CredentialIdentity & Record<string, unknown>) => Promise<Response | StatusReturn | UserType> | Response | StatusReturn | UserType;
27
27
  onCredentialsLoginError?: (context: {
28
28
  email: string;
29
29
  error: unknown;
package/dist/index.d.ts CHANGED
@@ -1189,5 +1189,7 @@ export * from './lockout/config';
1189
1189
  export * from './lockout/types';
1190
1190
  export { createInMemoryLockoutStore } from './lockout/inMemoryLockoutStore';
1191
1191
  export { createNeonLockoutStore, createPostgresLockoutStore, lockoutsTable } from './lockout/postgresLockoutStore';
1192
+ export { createRedisLockoutStore } from './lockout/redisLockoutStore';
1193
+ export type { RedisLike } from './stores/redis';
1192
1194
  export { createInMemoryAuditSink } from './audit/inMemoryAuditStore';
1193
1195
  export { auditEventsTable, createNeonAuditSink, createPostgresAuditSink } from './audit/postgresAuditStore';
package/dist/index.js CHANGED
@@ -2807,7 +2807,7 @@ var credentialsRegister = ({
2807
2807
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
2808
2808
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS
2809
2809
  }) => new Elysia5().use(sessionStore()).post(registerRoute, async ({
2810
- body: { email, password },
2810
+ body: { email, password, ...extraFields },
2811
2811
  cookie: { user_session_id },
2812
2812
  status,
2813
2813
  store: { session }
@@ -2828,6 +2828,7 @@ var credentialsRegister = ({
2828
2828
  return status("Conflict", "Email is already registered");
2829
2829
  }
2830
2830
  const created = await onCreateCredentialUser({
2831
+ ...extraFields,
2831
2832
  email: normalizedEmail
2832
2833
  });
2833
2834
  if (created instanceof Response || isStatusResponse(created)) {
@@ -2872,7 +2873,7 @@ var credentialsRegister = ({
2872
2873
  await onCredentialsLoginSuccess?.({ user: created, userSessionId });
2873
2874
  return status("Created", { status: "authenticated" });
2874
2875
  }, {
2875
- body: t5.Object({ email: t5.String(), password: t5.String() }),
2876
+ body: t5.Object({ email: t5.String(), password: t5.String() }, { additionalProperties: true }),
2876
2877
  cookie: t5.Cookie({ user_session_id: userSessionIdTypebox })
2877
2878
  });
2878
2879
 
@@ -15166,6 +15167,53 @@ var createPostgresLockoutStore = (db) => {
15166
15167
  }
15167
15168
  };
15168
15169
  };
15170
+ // src/lockout/redisLockoutStore.ts
15171
+ var DEFAULT_PREFIX = "auth:lockout:";
15172
+ var toRecord2 = (raw, key) => {
15173
+ const parsed = JSON.parse(raw);
15174
+ if (typeof parsed !== "object" || parsed === null)
15175
+ return;
15176
+ const failedAttempts = Reflect.get(parsed, "failedAttempts");
15177
+ const windowStartedAt = Reflect.get(parsed, "windowStartedAt");
15178
+ const lockedUntil = Reflect.get(parsed, "lockedUntil");
15179
+ if (typeof failedAttempts !== "number" || typeof windowStartedAt !== "number") {
15180
+ return;
15181
+ }
15182
+ return {
15183
+ failedAttempts,
15184
+ key,
15185
+ lockedUntil: typeof lockedUntil === "number" ? lockedUntil : undefined,
15186
+ windowStartedAt
15187
+ };
15188
+ };
15189
+ var createRedisLockoutStore = (redis, keyPrefix = DEFAULT_PREFIX) => {
15190
+ const read = async (key) => {
15191
+ const raw = await redis.get(keyPrefix + key);
15192
+ return raw ? toRecord2(raw, key) : undefined;
15193
+ };
15194
+ return {
15195
+ get: read,
15196
+ increment: async (key, windowMs) => {
15197
+ const now = Date.now();
15198
+ const existing = await read(key);
15199
+ const next = existing !== undefined && now - existing.windowStartedAt <= windowMs ? { ...existing, failedAttempts: existing.failedAttempts + 1 } : { failedAttempts: 1, key, windowStartedAt: now };
15200
+ await redis.set(keyPrefix + key, JSON.stringify(next), windowMs);
15201
+ return next;
15202
+ },
15203
+ lock: async (key, lockedUntil) => {
15204
+ const existing = await read(key) ?? {
15205
+ failedAttempts: 0,
15206
+ key,
15207
+ windowStartedAt: Date.now()
15208
+ };
15209
+ const ttlMs = Math.max(lockedUntil - Date.now(), 1);
15210
+ await redis.set(keyPrefix + key, JSON.stringify({ ...existing, lockedUntil }), ttlMs);
15211
+ },
15212
+ reset: async (key) => {
15213
+ await redis.del(keyPrefix + key);
15214
+ }
15215
+ };
15216
+ };
15169
15217
  // src/audit/inMemoryAuditStore.ts
15170
15218
  var createInMemoryAuditSink = () => {
15171
15219
  const events = [];
@@ -15393,6 +15441,7 @@ export {
15393
15441
  credentialRoutes,
15394
15442
  credentialResetTokensTable,
15395
15443
  createTotpKeyUri,
15444
+ createRedisLockoutStore,
15396
15445
  createPostgresMfaStore,
15397
15446
  createPostgresLockoutStore,
15398
15447
  createPostgresCredentialStore,
@@ -15436,5 +15485,5 @@ export {
15436
15485
  AuthIdentityConflictError
15437
15486
  };
15438
15487
 
15439
- //# debugId=7ACDDE7FAAAD2C7B64756E2164756E21
15488
+ //# debugId=44D2758802359A7064756E2164756E21
15440
15489
  //# sourceMappingURL=index.js.map