@absolutejs/auth 0.29.1 → 0.29.3

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.
@@ -22,7 +22,10 @@ export type CredentialsConfig<UserType> = {
22
22
  checkBreachesOnLogin?: boolean;
23
23
  credentialStore: CredentialStore;
24
24
  getUserByEmail: (email: string) => Promise<UserType | null | undefined> | UserType | null | undefined;
25
- isMfaRequired?: (user: UserType) => boolean | Promise<boolean>;
25
+ isMfaRequired?: (user: UserType, context?: {
26
+ headers: Record<string, string | undefined>;
27
+ ip?: string;
28
+ }) => boolean | Promise<boolean>;
26
29
  loginRoute?: RouteString;
27
30
  onCreateCredentialUser: (identity: CredentialIdentity & Record<string, unknown>) => Promise<Response | StatusReturn | UserType> | Response | StatusReturn | UserType;
28
31
  onCredentialsLoginError?: (context: {
package/dist/index.js CHANGED
@@ -3457,9 +3457,18 @@ var credentialsLogin = ({
3457
3457
  }) => new Elysia6().use(sessionStore()).post(loginRoute, async ({
3458
3458
  body: { email, password },
3459
3459
  cookie: { user_session_id },
3460
+ request,
3460
3461
  status,
3461
3462
  store: { session, unregisteredSession }
3462
3463
  }) => {
3464
+ const headerBag = {};
3465
+ request.headers.forEach((value, key) => {
3466
+ headerBag[key] = value;
3467
+ });
3468
+ const mfaContext = {
3469
+ headers: headerBag,
3470
+ ip: headerBag["cf-connecting-ip"] ?? headerBag["do-connecting-ip"] ?? headerBag["x-forwarded-for"]?.split(",")[0]?.trim() ?? undefined
3471
+ };
3463
3472
  const normalizedEmail = email.trim().toLowerCase();
3464
3473
  const lockState = lockoutGuard ? await lockoutGuard.check(normalizedEmail) : undefined;
3465
3474
  if (lockState?.locked) {
@@ -3483,7 +3492,7 @@ var credentialsLogin = ({
3483
3492
  if (requireEmailVerification && !credential.emailVerified) {
3484
3493
  return status("Forbidden", { status: "email_not_verified" });
3485
3494
  }
3486
- if (await isMfaRequired?.(user)) {
3495
+ if (await isMfaRequired?.(user, mfaContext)) {
3487
3496
  const compatibilityLayer = await createSessionCompatibilityLayer({
3488
3497
  authSessionStore,
3489
3498
  userSessionId: user_session_id.value
@@ -23217,5 +23226,5 @@ export {
23217
23226
  AuthIdentityConflictError
23218
23227
  };
23219
23228
 
23220
- //# debugId=7EEC3FFFBF5D362764756E2164756E21
23229
+ //# debugId=A629114DF39943A964756E2164756E21
23221
23230
  //# sourceMappingURL=index.js.map