Forest cannot authenticate the user for this request after migrating to version 8

@GuillaumeGautreau We upgraded our Forest Express Mongoose to version 8.7.1 everything is working fine on my local environment. On Development environment getting error when trying to access the dashboard.

Forest cannot authenticate the user for this request

Logs for your reference

[2022-06-21T10:25:09.731Z] - POST /forest/sessions-google 401 34.637 ms
[2022-06-21T10:32:39.405Z] - OPTIONS /forest/stats/Organization?timezone=Asia%2FCalcutta 204 1.727 ms
[2022-06-21T10:32:39.409Z] - OPTIONS /forest/stats/Report?timezone=Asia%2FCalcutta 204 1.282 ms
[2022-06-21T10:32:39.412Z] - OPTIONS /forest/stats/Report?timezone=Asia%2FCalcutta 204 2.148 ms
[2022-06-21T10:32:39.681Z] - POST /forest/stats/Organization?timezone=Asia%2FCalcutta 401 13.602 ms
[2022-06-21T10:32:39.689Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 401 5.518 ms
[2022-06-21T10:32:39.694Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 401 3.876 ms
[2022-06-21T10:35:57.165Z] - POST /forest/stats/Organization?timezone=Asia%2FCalcutta 401 5.043 ms
[2022-06-21T10:35:57.229Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 401 4.540 ms
[2022-06-21T10:35:57.260Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 401 4.868 ms
[2022-06-21T10:39:54.545Z] - OPTIONS /forest/sessions-google 204 2.642 ms
{
  code: '',
  message: 'Forest cannot authenticate the user for this request.'
}

Below are the code for refrence

const cors = require('cors');
const config = require('config');
const join = require('path');
const Liana = require('forest-express-mongoose');

module.exports = async function(app) {
  const mongoose = require('mongoose');

  const allowedOrigins = [/\.forestadmin\.com$/,/\.finicitydev\.com$/, /\.finicitystg\.com$/, /\.finicityreports\.com$/];
  const corsOptions = {
    origin: allowedOrigins.concat(new RegExp('null')),
    allowedHeaders: ['Authorization', 'X-Requested-With', 'Content-Type', 'Forest-Context-Url'],
    maxAge: 86400, // NOTICE: 1 day
    credentials: true,
  };
  app.use(cors(corsOptions));

  const forest = await Liana.init({
    configDir: join.resolve(__dirname, '../forest'),
    envSecret: config.FOREST_ENV_SECRET,
    authSecret: config.FOREST_AUTH_SECRET,
    objectMapping: mongoose,
    connections: { default: mongoose.connection },
  });
  app.use(forest);

  app.use('/forest', (request, response, next) => {
    if (Liana.PUBLIC_ROUTES.includes(request.path) || request.method === 'OPTIONS') {
      return next();
    }
    return Liana.ensureAuthenticated(request, response, next);
  });
  app.use('^(?!forest/?$).*', cors(corsOptions));
};```


Followed the step for migration [upgrade docs from v7 to v8 ][(https://docs.forestadmin.com/documentation/how-tos/maintain/upgrade-notes-sql-mongodb/upgrade-to-v8)](https://upgrade docs from v7 to v8 1)

Thanks in advance

Ok, so the problem is still that the schema is not sent to our servers. The route declared here is not present anymore on v7 or v8 of the agent. It has been replaced by a new authentication mechanism.

If the frontend continues to make requests to this route, it indicates that our server did not receive the information that you upgraded your agent. It means that the schema has not been sent, or that the env_secret does not match the right environment.

Can you please copy/paste the whole log from your agent?

@GuillaumeGautreau Now able to authenticate with latest version of forest-express-moongose 8.71.1 on development environment but the liana version is not updated it’s still 7.9..2

See the logs

REPORT TYPES  SEEDING - START
REPORT TYPES  SEEDING - # TRIES (0)
REPORT TYPES  SEEDING - # ADDED (0)
REPORT TYPES  SEEDING - # FAILURES (0)
REPORT TYPES  SEEDING - END
PRODUCT TYPE SEEDING - START
PRODUCT TYPE SEEDING - # TRIES (0)
PRODUCT TYPE SEEDING - # ADDED (0)
PRODUCT TYPE SEEDING - # FAILURES (0)
PRODUCT TYPE SEEDING - END
Initialization complete, starting server...
[forest] 🌳🌳🌳  Your configDir ("/home/app/server/forest") does not exist. Please make sure it is set correctly.
Thu, 23 Jun 2022 12:59:57 GMT body-parser deprecated undefined extended: provide extended option at server/lender-portal-server-app.js:161:20
(node:11) DeprecationWarning: Mongoose: the `isAsync` option for custom validators is deprecated. Make your async validators return a promise instead: https://mongoosejs.com/docs/validation.html#async-custom-validators
Listening on port 8080
index created successfully
[forest] 🌳🌳🌳  Checking need for apimap update...
[forest] 🌳🌳🌳  No change in apimap, nothing sent to Forest.
[2022-06-23T13:11:57.721Z] - POST /forest/authentication 200 854.196 ms
[2022-06-23T13:11:57.723Z] - POST /forest/authentication 200 887.072 ms
[2022-06-23T13:12:00.580Z] - OPTIONS /forest/authentication/callback?code=GMttfHYGilzhPMphXDI_v4-KGFIOrOJJrdTHS30_Sbs-mac7tMAMOj_VCYjH6rF2&state=%7B%22renderingId%22%3A49322%7D 204 2.311 ms
[2022-06-23T13:12:00.843Z] - OPTIONS /forest/authentication/callback?code=masw74gX7gwZAYp6r9WhrWNS-v9-nLfzR_JzRqOLlzGTGD9xSuNpOejXxJCDWB0x&state=%7B%22renderingId%22%3A49322%7D 204 3.434 ms
[2022-06-23T13:12:02.153Z] - GET /forest/authentication/callback?code=GMttfHYGilzhPMphXDI_v4-KGFIOrOJJrdTHS30_Sbs-mac7tMAMOj_VCYjH6rF2&state=%7B%22renderingId%22%3A49322%7D 200 1272.202 ms
[2022-06-23T13:12:03.038Z] - GET /forest/authentication/callback?code=masw74gX7gwZAYp6r9WhrWNS-v9-nLfzR_JzRqOLlzGTGD9xSuNpOejXxJCDWB0x&state=%7B%22renderingId%22%3A49322%7D 200 1891.299 ms
[2022-06-23T13:12:03.373Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 200 885.295 ms
[2022-06-23T13:12:03.374Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 200 913.544 ms
[2022-06-23T13:12:03.388Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 200 12.090 ms
[2022-06-23T13:12:03.462Z] - POST /forest/stats/Organization?timezone=Asia%2FCalcutta 200 406.639 ms
[2022-06-23T13:12:03.702Z] - POST /forest/stats/Report?timezone=Asia%2FCalcutta 200 17.684 ms
[2022-06-23T13:12:03.704Z] - POST /forest/stats/Organization?timezone=Asia%2FCalcutta 200 10.579 ms

Hello @Vishnu_Gupta,

First of all, we can see an error with the configuration of configDir. Its default value is ./forest which I suppose is used in your case. Don’t you have a forest directory on your server? Did you move the code specific to forest admin in another directory?

Regarding the issue with the schema file, can you please copy and share here the content of the meta property inside the file named .forestadmin-schema.json in your server directory?

It should look like something like that:

{
  // [...]
  // I only need this property, at the end of the file
  "meta": {
    "liana": "forest-express-sequelize",
    "liana_version": "8.5.4",
    "stack": {
      "database_type": "postgres",
      "engine": "nodejs",
      "engine_version": "16.14.0",
      "orm_version": "6.6.5"
    }
  }
}