CodeIgniter Forums

Full Version: Multiple Filter on single route
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:ConfusedignInJwt', ['filter' => ['cors','isSignIn','validation']]);
I chime in every time I this comes up: we definitely need this! If you or someone would like to make a Pull Request it is for sure a desired feature. Here’s my Feature Request from two years ago: https://github.com/codeigniter4/CodeIgni...ssues/2078
yes ci4 support multiple filter (middleware) on some path(https://api/v1/*)
it should be global filter to work after or before request

but that way no works on routes
that's its problem
(09-19-2021, 10:32 PM)iRedds Wrote: [ -> ]https://github.com/codeigniter4/CodeIgniter4/pull/5108

A great solution, thank you!!!