node.jshttp-redirectroutesstrapikoa

Strapi how to redirect to different route after login, v4+


I am working with Strapi, and I am trying to modify the default behaviour after a user logs in. By default, Strapi redirects users to the /admin welcome page, which includes various links and information. However, I want users to be redirected directly to a specific tables page within the admin panel after login. I attempted to change middleware, but it did not work as expected.


Solution

  • after some hassle some customisation I had to make.

    the solution below changing all the default routes to /admin/content-manager but that fully depends what default route can be redirected

    in src/middlewares/admin-redirect.js

    module.exports = (_config, { strapi }) => {
      const redirects = ['/', '/index.html','/admin'].map((path) => ({
          method: 'GET',
          path,
          handler: (ctx) => ctx.redirect('/admin/content-manager'),
          config: { auth: false },
      }));
    
      strapi.server.routes(redirects);
    };
    

    in config/middlewares.js

    module.exports = [
      // all previous items ...
      { resolve: './src/middlewares/admin-redirect' }, // add this line
    ];
    

    And all set!