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: 10 additions & 0 deletions apps/control-panel-app/src/common/filters/http-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
let message = "Internal server error";
let errorCode = "INTERNAL_SERVER_ERROR";
let errorDetail: string | undefined;
let retryAfterSeconds: number | undefined;

if (exception instanceof HttpException) {
status = exception.getStatus();
Expand Down Expand Up @@ -65,6 +66,14 @@ export class HttpExceptionFilter implements ExceptionFilter {
errorCode = body.errorCode;
}

if (
typeof body.retryAfterSeconds === "number" &&
Number.isFinite(body.retryAfterSeconds) &&
body.retryAfterSeconds > 0
) {
retryAfterSeconds = Math.ceil(body.retryAfterSeconds);
}

if (typeof body.error === "string") {
const candidate = body.error.trim();
if (
Expand Down Expand Up @@ -96,6 +105,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
errorCode,
message,
...(errorDetail ? { error: errorDetail } : {}),
...(retryAfterSeconds ? { retryAfterSeconds } : {}),
};

response.status(status).json({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ErrorResponse {
errorCode: string;
message: string;
error?: string;
retryAfterSeconds?: number;
}
4 changes: 4 additions & 0 deletions apps/control-panel-app/src/constants/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export const ERROR_MESSAGES = {
OTP_EXPIRED: "OTP expired",
OTP_NOT_VERIFIED: "OTP not verified",
MAX_OTP_ATTEMPTS: "OTP attempts exhausted, please try again later",
EMAIL_NOT_VERIFIED: "Email not verified",
OTP_EXPIRED_OR_INVALID: "OTP expired or invalid",
OTP_RESEND_LIMIT_REACHED:
"You have reached the resend limit. Try again after {minutes} minutes.",
},

PROFILE: {
Expand Down
10 changes: 6 additions & 4 deletions apps/control-panel-app/src/constants/success.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ export const SUCCESS_MESSAGES = {
},

AUTH: {
SIGNUP: "User registered successfully",
SIGNUP: "Account created. Check your email for a verification code.",
LOGIN: "User logged in successfully",
REFRESH: "Tokens refreshed successfully",
LOGOUT: "User logged out successfully",
LOGOUT_ALL: "Logged out from all devices successfully",
PROFILE: "Profile fetched successfully",
RESET_PASSWORD: "Password updated successfully",
OTP_SENT: "OTP sent successfully",
OTP_VERIFIED: "OTP verified successfully",
PASSWORD_RESET: "Password updated successfully",
OTP_SENT: "Verification code sent to your email.",
OTP_RESENT: "A new verification code has been sent to your email.",
EMAIL_VERIFIED: "Your email has been verified. You can sign in now.",
RESET_CODE_VERIFIED: "Code verified. You can set a new password.",
PASSWORD_RESET: "Your password has been updated. You can sign in now.",
},

PROFILE: {
Expand Down
8 changes: 8 additions & 0 deletions apps/control-panel-app/src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ export class AuthController {
return this.authService.forgotPassword(forgotPasswordDto);
}

/**
* Resend registration OTP
*/
@Post("resend-otp")
async resendOtp(@Body() forgotPasswordDto: ForgotPasswordDto) {
return this.authService.resendOtp(forgotPasswordDto.email);
}

/**
* Verify OTP
*/
Expand Down
2 changes: 2 additions & 0 deletions apps/control-panel-app/src/modules/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { UserCodeEntity } from "./entities/user-codes.entity";
import { UsersModule } from "../users/users.module";
import { AuthCookieService } from "./services/auth-cookie.service";
import { AuthSessionLookupService } from "./services/auth-session-lookup.service";
import { EmailService } from "../email/email.service";

@Module({
imports: [
Expand Down Expand Up @@ -43,6 +44,7 @@ import { AuthSessionLookupService } from "./services/auth-session-lookup.service
AuthService,
AuthCookieService,
AuthSessionLookupService,
EmailService,
JwtStrategy,
RefreshJwtStrategy,
],
Expand Down
Loading
Loading