ci4 needs add new feature multiple filters on route like express.js
look at codes
Code:
import { Router } from "express";
import AuthController from "../controllers/auth.controller";
import { Routes } from "../../../core/interfaces/routes.interface";
import authMiddleware from "../middlewares/auth.middleware";
import validationMiddleware from "../../../core/middlewares/validation.middleware";
import { AuthSignupValidation } from "../validations/auth.signup.validation";
import { AuthSigninValidation } from "../validations/auth.signin.validation";
import { AuthForgotValidation } from "../validations/auth.forgot.validation";
import { AuthActivateTokenEmailValidation } from "../validations/auth.activate.token.email.validation";
import { AuthSendActivateEmailValidation } from "../validations/auth.send.activate.email.validation";
import { AuthSendActivatePhoneValidation } from "../validations/auth.send.activate.phone.validation";
import { AuthResetPasswordEmailValidation } from "../validations/auth.reset.password.email.validation";
import { AuthResetPasswordPhoneValidation } from "../validations/auth.reset.password.phone.validation";
import { AuthActivateTokenPhoneValidation } from "../validations/auth.activate.token.phone.validation";
import { RecaptchaV3 } from "express-recaptcha";
import { authConfig } from "../configs/auth.config";
import isSignInMiddleware from "../middlewares/is.sign.in.middleware";
class AuthRoute implements Routes {
public path = "/api/auth/";
public router = Router();
public controller = new AuthController();
// public recaptcha = new RecaptchaV3(authConfig.captcha.siteKey,
// authConfig.captcha.secretKey,
// {callback: 'cb'});
// //this.recaptcha.middleware.verify
constructor() {
this.initializeRoutes();
}
private initializeRoutes() {
this.router.post(`${this.path}signin`, isSignInMiddleware, validationMiddleware(AuthSigninValidation, "body"), this.controller.signIn);
this.router.post(`${this.path}signout`, authMiddleware, this.controller.signOut);
this.router.post(`${this.path}signup`, isSignInMiddleware, validationMiddleware(AuthSignupValidation, "body"), this.controller.signUp);
this.router.post(`${this.path}activate-account-email`, isSignInMiddleware, validationMiddleware(AuthActivateTokenEmailValidation, "body"), this.controller.activationViaEmail);
this.router.post(`${this.path}send-activate-email`, isSignInMiddleware, validationMiddleware(AuthSendActivateEmailValidation, "body"), this.controller.sendActivateCodeViaEmail);
this.router.post(`${this.path}activate-account-sms`, isSignInMiddleware, validationMiddleware(AuthActivateTokenPhoneValidation, "body"), this.controller.activationViaSms);
this.router.post(`${this.path}send-activate-sms`, isSignInMiddleware, validationMiddleware(AuthSendActivatePhoneValidation, "body"), this.controller.sendActivateCodeViaSms);
this.router.post(`${this.path}forgot`, isSignInMiddleware, validationMiddleware(AuthForgotValidation, "body"), this.controller.forgot);
this.router.post(`${this.path}reset-password-email`, isSignInMiddleware, validationMiddleware(AuthResetPasswordEmailValidation, "body"), this.controller.resetPasswordViaEmail);
this.router.post(`${this.path}reset-password-sms`, isSignInMiddleware, validationMiddleware(AuthResetPasswordPhoneValidation, "body"), this.controller.resetPasswordViaSms);
}
}
make ci4 even stronger then before
for example
$routes->post('signin-jwt', 'Auth:
ignInJwt', ['filter' => ['cors','isSignIn','validation']]);
Enlightenment Is Freedom