fix(sign-in): ログイン失敗時のエラーコードの統一 (MisskeyIO#843)
This commit is contained in:
parent
6542ad4a12
commit
8abe8aecee
26 changed files with 53 additions and 25 deletions
|
@ -122,10 +122,12 @@ export class SigninApiService {
|
|||
return;
|
||||
}
|
||||
|
||||
const loginWithEmail = username.includes('@');
|
||||
|
||||
// Fetch user
|
||||
const profile = await this.userProfilesRepository.findOne({
|
||||
relations: ['user'],
|
||||
where: username.includes('@') ? {
|
||||
where: loginWithEmail ? {
|
||||
email: username,
|
||||
emailVerified: true,
|
||||
user: {
|
||||
|
@ -143,21 +145,21 @@ export class SigninApiService {
|
|||
if (!user || !profile) {
|
||||
logger.error('No such user.');
|
||||
return error(403, {
|
||||
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
|
||||
id: loginWithEmail ? '932c904e-9460-45b7-9ce6-7ed33be7eb2c' : '6cc579cc-885d-43d8-95c2-b8c7fc963280',
|
||||
});
|
||||
}
|
||||
|
||||
if (user.isDeleted && user.isSuspended) {
|
||||
logger.error('No such user. (logical deletion)');
|
||||
return error(403, {
|
||||
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
|
||||
id: loginWithEmail ? '932c904e-9460-45b7-9ce6-7ed33be7eb2c' : '6cc579cc-885d-43d8-95c2-b8c7fc963280',
|
||||
});
|
||||
}
|
||||
|
||||
if (user.isSuspended) {
|
||||
logger.error('User is suspended.');
|
||||
return error(403, {
|
||||
id: 'e03a5f46-d309-4865-9b69-56282d94e1eb',
|
||||
id: loginWithEmail ? '932c904e-9460-45b7-9ce6-7ed33be7eb2c' : 'e03a5f46-d309-4865-9b69-56282d94e1eb',
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -180,27 +182,26 @@ export class SigninApiService {
|
|||
if (!profile.twoFactorEnabled) {
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
const meta = await this.metaService.fetch();
|
||||
if (meta.enableHcaptcha && meta.hcaptchaSecretKey) {
|
||||
await this.captchaService.verifyHcaptcha(meta.hcaptchaSecretKey, body['hcaptcha-response']).catch(err => {
|
||||
throw new FastifyReplyError(400, err);
|
||||
});
|
||||
}
|
||||
try {
|
||||
if (meta.enableHcaptcha && meta.hcaptchaSecretKey) {
|
||||
await this.captchaService.verifyHcaptcha(meta.hcaptchaSecretKey, body['hcaptcha-response']);
|
||||
}
|
||||
|
||||
if (meta.enableMcaptcha && meta.mcaptchaSecretKey && meta.mcaptchaSitekey && meta.mcaptchaInstanceUrl) {
|
||||
await this.captchaService.verifyMcaptcha(meta.mcaptchaSecretKey, meta.mcaptchaSitekey, meta.mcaptchaInstanceUrl, body['m-captcha-response']).catch(err => {
|
||||
throw new FastifyReplyError(400, err);
|
||||
});
|
||||
}
|
||||
if (meta.enableMcaptcha && meta.mcaptchaSecretKey && meta.mcaptchaSitekey && meta.mcaptchaInstanceUrl) {
|
||||
await this.captchaService.verifyMcaptcha(meta.mcaptchaSecretKey, meta.mcaptchaSitekey, meta.mcaptchaInstanceUrl, body['m-captcha-response']);
|
||||
}
|
||||
|
||||
if (meta.enableRecaptcha && meta.recaptchaSecretKey) {
|
||||
await this.captchaService.verifyRecaptcha(meta.recaptchaSecretKey, body['g-recaptcha-response']).catch(err => {
|
||||
throw new FastifyReplyError(400, err);
|
||||
});
|
||||
}
|
||||
if (meta.enableRecaptcha && meta.recaptchaSecretKey) {
|
||||
await this.captchaService.verifyRecaptcha(meta.recaptchaSecretKey, body['g-recaptcha-response']);
|
||||
}
|
||||
|
||||
if (meta.enableTurnstile && meta.turnstileSecretKey) {
|
||||
await this.captchaService.verifyTurnstile(meta.turnstileSecretKey, body['turnstile-response']).catch(err => {
|
||||
throw new FastifyReplyError(400, err);
|
||||
if (meta.enableTurnstile && meta.turnstileSecretKey) {
|
||||
await this.captchaService.verifyTurnstile(meta.turnstileSecretKey, body['turnstile-response']);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`Invalid request: captcha verification failed: ${err}`);
|
||||
return await fail(403, {
|
||||
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +230,7 @@ export class SigninApiService {
|
|||
} catch (e) {
|
||||
logger.error('Invalid request: Unable to authenticate with two-factor token.');
|
||||
return await fail(403, {
|
||||
id: 'cdf1235b-ac71-46d4-a3a6-84ccce48df6f',
|
||||
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -251,7 +252,7 @@ export class SigninApiService {
|
|||
} else {
|
||||
logger.error('Invalid request: Unable to authenticate with WebAuthn credential.');
|
||||
return await fail(403, {
|
||||
id: '93b86c4b-72f9-40eb-9815-798928603d1e',
|
||||
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue