After configuring captcha2
This commit is contained in:
parent
aea87f2dbb
commit
475951a3a0
@ -310,8 +310,10 @@ export async function login(
|
||||
throw e;
|
||||
}
|
||||
|
||||
const settings = await settingsRepository.getSettings();
|
||||
const failedCount = await userRepository.getFailedLoginCount(user.id);
|
||||
const [settings, failedCount] = await Promise.all([
|
||||
settingsRepository.getSettings(),
|
||||
userRepository.getFailedLoginCount(user.id),
|
||||
]);
|
||||
const afterFailures = settings.login_captcha_after_failures;
|
||||
if (afterFailures > 0 && failedCount >= afterFailures) {
|
||||
try {
|
||||
@ -382,8 +384,10 @@ export async function login(
|
||||
}
|
||||
}
|
||||
|
||||
await loginLockoutService.clearLoginFailures(user.id);
|
||||
const payload = await buildJwtPayload(user);
|
||||
const [payload] = await Promise.all([
|
||||
buildJwtPayload(user),
|
||||
loginLockoutService.clearLoginFailures(user.id),
|
||||
]);
|
||||
const accessExpiry = settings.access_token_expiry || config.jwt.accessExpiry;
|
||||
const accessToken = jwt.sign(payload, config.jwt.secret, { expiresIn: accessExpiry } as jwt.SignOptions);
|
||||
const refreshToken = uuidv4();
|
||||
@ -393,8 +397,11 @@ export async function login(
|
||||
ipAddress: auditContext?.ipAddress,
|
||||
userAgent: auditContext?.userAgent,
|
||||
});
|
||||
await enforceConcurrentSessionLimit(user.id, auditContext);
|
||||
// Session trim + telemetry must not block the login response.
|
||||
void enforceConcurrentSessionLimit(user.id, auditContext).catch(() => undefined);
|
||||
if (auditContext) {
|
||||
void (async () => {
|
||||
try {
|
||||
await auditLogRepository.create({
|
||||
userId: user.id,
|
||||
action: 'login',
|
||||
@ -420,6 +427,10 @@ export async function login(
|
||||
}
|
||||
const risk = assessLoginRisk(fingerprint);
|
||||
void recordLoginRisk(user.id, risk, notifyCtx);
|
||||
} catch {
|
||||
/* best-effort post-login side effects */
|
||||
}
|
||||
})();
|
||||
}
|
||||
void mergeVisitorSupportForUser(user.id, auditContext?.visitorSupportToken);
|
||||
const decoded = jwt.decode(accessToken) as { exp: number };
|
||||
|
||||
@ -235,7 +235,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
state.errorMessage != null) {
|
||||
final msg = state.errorMessage!
|
||||
.replaceFirst('Exception: ', '');
|
||||
if (state.isCaptchaChallenge || _captchaRequired) {
|
||||
// Only refresh the math challenge on captcha errors.
|
||||
// Other failures (wrong password/2FA) must keep the current prompt.
|
||||
if (state.isCaptchaChallenge) {
|
||||
_applyMathChallenge(state.captcha);
|
||||
}
|
||||
if (state.isEmailNotVerified) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user