Authentication Error

Expected behavior

We have done the complete setup as instructed in the documentation. Ideally, we should be able to see the dashboard with data populated in it from the DB.

Actual behavior

But we are facing the following 2 issues:

Issue 1:

It says unable to authenticate, we also tried with forest-cli login and with a proper credential in hand but we are getting nothing on our plate.

Issue 2:
When we run our application on port:8000
The first time it runs perfectly but when we do some changes on the application we are getting message 8000 is already running. we are using nodemon on the server to watch and run our application.

Could you please help me out with what’s wrong with the configuration.

Hello @Anupam_Rana,

Can you please check your server logs and share with me the failing request with the associated response message?

I can see from your screenshot that you are launching your server from MConnectServer repository which is a name that differ from MConnectApplication, is that normal?

Kind regards,
Louis

Hello, We have checked our logs on the server but we are not getting in request logs.

MConnectApplication is just project name for forest admin but the MConnectServer is a repository name and I tried giving names interchangeably but nothing is happening on Portal.

I am attaching a few screenshots of the issues with this thread, hope it will help




Can you check that you can access your application in your browser http://localhost:8000 please?

Do you have any other error in the console available in the chrome dev tool?

At first, your configuration seems great. :slight_smile:

Yes, the Backend application is running on Port:8000


What is the status code of the /forest/authentication request, and can you share me all the request (from the network tab of the chrome dev tool) please? :slight_smile:

I am not able to upload Chrome Network har file here because that is too big as per the alert message.

Maybe you can just send some screenshot? :slight_smile:

Processing: Forest Admin ‣ Data ‣ Hcp Settings.mp4…










Thanks for sharing all of these screenshots, it helps a lot ! :pray:

It seems that you have a CORS error on the authentication route according to your last screenshot.

Can you try to define this before the application listening part as it was suggested in the documentation?

app.use(await forest.init({
 envSecret: process.env.FOREST_ENV_SECRET,
 authSecret: process.env.FOREST_AUTH_SECRET,
 objectMapping: models,
 connections: { default: connection },
}));

Can you also try to hardcode http://localhost:8000 in the allowed origin?

And can you share me the headers that are sent to the OPTIONS authentication request that responds a 204 status code please?

Thanks,

app.use(await forest.init({
envSecret: process.env.FOREST_ENV_SECRET,
authSecret: process.env.FOREST_AUTH_SECRET,
objectMapping: models,
connections: { default: connection },
}));

can we use await without asynchronous function?
I tried but getting a syntactical error.

Thanks, I manage to make it work, I have changed few things in terms of initializing forest admin.

INSTEAD OF THIS

app.use(await forest.init({
envSecret: process.env.FOREST_ENV_SECRET,
authSecret: process.env.FOREST_AUTH_SECRET,
objectMapping: models,
connections: { default: connection },
}));

I DID THIS

forest.init({
    envSecret: process.env.FOREST_ENV_SECRET,
    authSecret: process.env.FOREST_AUTH_SECRET,
    objectMapping:require('mongoose'),
    connections: { default: mongooseConnection },
   }).then((FAMiddleware) => {
    app.use(FAMiddleware);
   });

INSTEAD OF THIS

app.use('/forest/authentication',cors(corsConfig)); // it returns status 404`

I DID THIS

app.post('/forest/authentication',cors(corsConfig)); // it returns status 200`
2 Likes