401 in production and staging environment

Hello,

I successfully deployed my admin backend to a remote server with my development env.
Then I created a production and a staging env that I deployed to others remote server with the exact same config for the proxy.
I copy/paste the environment variable provided in the wizard.
The backend return HTTP 401 error for production and staging env.
If I try to launch the server locally with my production or staging .env file, I got the same error.

Expected behavior

When creating production or remote environment my data should be accessible.
My development env is on a remote server too and is working as expected.

Actual behavior

“Cannot reach your data
Your server may be down or your database connection broken.” Error.
401 error on server log.
This error is both on production and staging env.
This error appear both locally and on remote server.

Failure Logs

GET /forest/adonisSchema/count?fields%5BadonisSchema%5D=batch%2Cid%2CmigrationTime%2Cname&searchExtended=0&timezone=Europe%2FParis 401 56 - 0.964 ms

Do you have any logs on your lianas ? And what is the response of the failed request on your browser ?

Thanks for your reply.
How can I check lianas logs ?

The failed request on my browser returned:

{
  "errors": [
    {
      "status": 401,
      "detail": "Forest cannot authenticate the user for this request."
    }
  ]
}

Hi @nasrat-v ,

A Liana are classic node app.
It produces log lines to the standard output, so how to see them depends on how you deployed the liana.
Additionally, liana contains a .env file with a LOG_LEVEL key you can set to error, info, or debug.

Regards

Hi @Sliman_Medini,

I’m confused about Liana.
I followed the tutorial to setup the admin backend locally.
I never installed Liana.
After setting my production variable in the .env file, I run npm start to start the server locally.

When connecting to the dashboard the server logs this

Your application is listening on port 3310. Your admin panel is available here: https://app.forestadmin.com/projects
GET /forest/adonisSchema?fields%5BadonisSchema%5D=batch%2Cid%2CmigrationTime%2Cname&page%5Bnumber%5D=1&page%5Bsize%5D=15&searchExtended=0&sort=-id&timezone=Europe%2FParis 401 56 - 22.603 ms

As you can see I received a 401 Unauthorized. The message error in the browser is Forest cannot authenticate the user for this request.

I really don’t understand why this error doesn’t happened in development env.
Do I miss something to start the server with another environment than development ?

Hello @nasrat-v,

Did you look at the network tab in you browser devtools?
Is there any information that could help us?
A warning or anything?

Did you check your CORS parameters and environment variables?

Let me know :wink:

I’m having this exact same issue. All I know is that it’s coming from right here. Same situation (localhost works, production doesn’t). Have you had any luck solving it @nasrat-v?

Edit: Actually not exactly the same, for me the 401 is from: /forest/authentication/callback

I found out the reason for this in my case. It didn’t like that I added a path to the server’s URL (https://webapp.com/admin, rather than e.g. https://admin.webapp.com, which does work). To do this, I added express.Router() to app.js and put the whole app behind /admin, which works in general, except for this liana authentication thing or whatever, so I switched to a subdomain, which isn’t ideal in my case. Is there a way to have a URL with a path otherwise?

Hi @yousefamar !
Did you add the prefix to your APPLICATION_URL ?
We recently fixed an issue related to that, if you can, upgrade to the latest version !

Thanks for the info @anon94532230! I did indeed add it to my APPLICATION_URL at first (both env as well as on app.forestadmin.com) but then I did the Router thing because while app.forestadmin.com was making requests to /my-path/forest etc (as it should), the server was still serving from /. Is this a known issue?

My forest-admin is at 8.1.0 currently btw, so that fix (8.0.4) should be in there already.

In case it’s pertinent, the modification I made to app.js was:

const router = express.Router();
let app = express();
app.use('/admin', router);
const _app = app;
app = router;

in the beginning, and then

module.exports = _app;

in the end, such that everything was behind /admin

The APPLICATION_URL is not used to define a path prefix, that’s why it was serving from ./ :slight_smile:
Is it working now ?

1 Like