Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/backend/src/server/api/endpoints/i/2fa/key-done.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export const meta = {
id: '0d7ec6d2-e652-443e-a7bf-9ee9a0cd77b0',
},

incorrectTotp: {
message: 'The one-time password is incorrect or has expired.',
code: 'INCORRECT_TOTP',
id: '57e56c36-e07e-49ab-97fb-7dc8a5b4cd50',
},

twoFactorNotEnabled: {
message: '2fa not enabled.',
code: 'TWO_FACTOR_NOT_ENABLED',
Expand Down Expand Up @@ -76,13 +82,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {

if (profile.twoFactorEnabled) {
if (token == null) {
throw new Error('authentication failed');
throw new ApiError(meta.errors.incorrectTotp);
}

try {
await this.userAuthService.twoFactorAuthenticate(profile, token);
} catch (_) {
throw new Error('authentication failed');
throw new ApiError(meta.errors.incorrectTotp);
}
}

Expand Down
10 changes: 8 additions & 2 deletions packages/backend/src/server/api/endpoints/i/2fa/register-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export const meta = {
id: '38769596-efe2-4faf-9bec-abbb3f2cd9ba',
},

incorrectTotp: {
message: 'The one-time password is incorrect or has expired.',
code: 'INCORRECT_TOTP',
id: '0606da0a-a3c3-4215-8b87-30ecb63475c1',
},

twoFactorNotEnabled: {
message: '2fa not enabled.',
code: 'TWO_FACTOR_NOT_ENABLED',
Expand Down Expand Up @@ -76,13 +82,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {

if (profile.twoFactorEnabled) {
if (token == null) {
throw new Error('authentication failed');
throw new ApiError(meta.errors.incorrectTotp);
}

try {
await this.userAuthService.twoFactorAuthenticate(profile, token);
} catch (_) {
throw new Error('authentication failed');
throw new ApiError(meta.errors.incorrectTotp);
}
}

Expand Down
Loading