Error on PermissionMiddleware smartAction use

Hi there

Expected behavior

Using permissionMiddleware.smartAction() without any trouble

Failure Logs

Error: Impossible to retrieve the smart action at endpoint /forest/actions/ubo/create/ and method POST

Context

Smart Action decorator :

@Post("forest/actions/ubo/create")

Our middleware :

@Injectable()
export class SmartActionPermissionMiddleware implements NestMiddleware {
  async use(req, res, next) {
    if (req.body.data.attributes.collection_name) {
      const permissionMiddleware = new forest.PermissionMiddlewareCreator(
        req.body.data.attributes.collection_name,
      );
      if(Array.isArray(permissionMiddleware.smartAction())) {
        await Promise.all(permissionMiddleware.smartAction().map(middleware => new Promise((resolve, reject) => {
          middleware(req, res, resolve)
        })))
        return next();

      }
      return permissionMiddleware.smartAction()(req, res, next);
    }
    return next();
  }
}

We saw on your commit that you verify the smartActionEndpoint adding the request.path to the request.baseUrl.
The request.path is equal to / and so :

forest/actions/ubo/create != forest/actions/ubo/create/

Is there something to change on our side to avoid that error ?

  • Package Version: 8.2.8
  • Express Version: 4.17.1
  • Sequelize Version: 5.22.3
  • Database Dialect: postgresql
  • Database Version:
  • Project Name: Swan Back-Office

Hey @Quentin_Giraud,

Thanks for your message :raised_hands:

Just to be sure I understand your issue here:

  • Are you facing a regression with this behaviour?
  • Your request.baseUrl is equal to forest/actions/ubo/create and your request.path is equal to /?
    This is very strange your baseURL should not be equal to the all route…
  • Are you facing a regression with this behaviour?

Indeed since our migration to v8

  • Your request.baseUrl is equal to forest/actions/ubo/create and your request.path is equal to / ?
    This is very strange your baseURL should not be equal to the all route…

Exactly, when I check, baseUrl is equal to forest/actions/ubo/create and path to /

Thanks for your help :pray:t2:

Hey @Quentin_Giraud,

So I guess you are using an “in-app” version of Forest Admin (you installed the forest-express-sequelize package directly in your main backend, you did not generate a separated admin backend)?

I guess the issue you’re facing is due to the way your router is defined.
In our generated admin backend, we are using app.use('/forest' in our app.js and then on the specific route we use router.post('/actions/name-of-the-action'. So this router baseURL is /forest and the path /actions/name-of-the-action (from Express behaviour).
Could you tell me how your router is defined then?

Then, we will of course find a way or push a fix to solve your use case!

Thanks a lot for bringing that up and sharing it with us.
Cheers!

1 Like

Hello @Quentin_Giraud,

Did you get the chance to see this message yet?

Cheers.