# Authentication loading indefinitely and no error message appears

**URL:** <https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771>\
**Category:** Help me!\
**Tags:** howtos, setup\
**Created:** [January 21, 2025, 10:57pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771 "2025-01-21T22:57:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilyas](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@ilyas](https://community.forestadmin.com/u/ilyas)\
**Post date:** [January 21, 2025, 10:57pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/1 "2025-01-21T22:57:55Z")

</div>

## Feature(s) impacted

The Forest Admin agent authentication process and its integration with MongoDB using `@forestadmin/datasource-mongoose`.

## Observed behavior

The Forest Admin panel displays the message:  
**“Unlocking your data. We are validating your identity.”**  
The loading modal spins indefinitely, and the authentication process does not complete.  
ps : nodejs receives the post request with renderingId

The Node.js application logs the following messages during startup:

Your application is listening on port 3310.  
Connected to MongoDB successfully.  
Registered models: [‘users’]  
Applying users collection customizations  
Customizing users collection  
Adding Smart Action to users collection  
Adding Smart Segment to users collection  
info: Successfully mounted on Express.js  
warning: Using unspecified flattenMode. Please refer to the documentation to update your code:

> **[Mongoose | Node.js Developer Guide](https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/provided-data-sources/mongoose)**

Forest Admin panel is ready.  
info: Schema was not updated since last run (hash: 090377f3dcc077f5326d0c2256c73b223414fb64)  
POST /forest/authentication - - - - ms

## Context

- **Project name:** `dibsy-forest`
- **Team name:** `dibsy`
- **Environment name:** Development
- **Agent technology:** Node.js
- **Agent (Forest package) name & version:**
  - `@forestadmin/agent`: `^1.57.1`
  - `@forestadmin/datasource-mongoose`: `^1.8.9`

- **Database type:** MongoDB
- **Recent changes made on your end:**
  - Migrated from `forest-express-mongoose` to the new `@forestadmin/agent` architecture.
  - Updated the `forestadmin.js` and `app.js`:

```javascript
const chalk = require('chalk');

```

const { createAgent } = require(‘@forestadmin/agent’);  
const { createMongooseDataSource } = require(‘@forestadmin/datasource-mongoose’);  
const mongoose = require(‘mongoose’);  
const configureUsersCollection = require(‘../forest/users’);  
const usersModel = require(‘../models/users’);

module.exports = async function forestadmin(app) {  
try {  
// Connect to MongoDB  
const connection = await mongoose.connect(process.env.DATABASE\_URL, {  
useNewUrlParser: true,  
useUnifiedTopology: true,  
});

```
console.log(chalk.green('Connected to MongoDB successfully.'));
usersModel(mongoose); // Register the users model

console.log('Registered models:', mongoose.modelNames());

// Initialize Forest Admin agent
const agent = createAgent({
  authSecret: process.env.FOREST_AUTH_SECRET,
  envSecret: process.env.FOREST_ENV_SECRET,
  isProduction: process.env.NODE_ENV === 'production',
});

// Add Mongoose data source with flattenMode configuration
agent.addDataSource(
  createMongooseDataSource(connection)
);

console.log('Applying users collection customizations'); // Debug log
configureUsersCollection(agent);

// Mount Forest Admin routes
await agent.mountOnExpress(app);

// Start the agent.
agent.start().catch(error => {
  console.error('\x1b[31merror:\x1b[0m Forest Admin agent failed to start\n');
  console.error('');
  console.error(error.stack);
  process.exit(1);
});

console.log(chalk.cyan('Forest Admin panel is ready.'));

```

} catch (error) {  
console.error(chalk.red(‘Failed to initialize Forest Admin:’), error);  
process.exit(1);  
}  
};  
app.js :

require(‘dotenv’).config();  
const express = require(‘express’);  
const path = require(‘path’);  
const cookieParser = require(‘cookie-parser’);  
const bodyParser = require(‘body-parser’);  
const cors = require(‘cors’);  
const morgan = require(‘morgan’);  
const forestadmin = require(‘./middlewares/forestadmin’);

const app = express();

let allowedOrigins = [/.forestadmin.com$/, /localhost:\d{4}$/];  
if (process.env.CORS\_ORIGINS) {  
allowedOrigins = allowedOrigins.concat(process.env.CORS\_ORIGINS.split(‘,’));  
}

const corsConfig = {  
origin: allowedOrigins,  
maxAge: 86400,  
credentials: true,  
};

// Middleware setup  
app.use(morgan(‘tiny’));

// Set CORS for authentication routes  
app.use(  
‘/forest/authentication’,  
cors({  
…corsConfig,  
origin: corsConfig.origin.concat(‘null’),  
})  
);  
app.use(cors(corsConfig));

// Body parsers and cookie parser  
app.use(bodyParser.json());  
app.use(bodyParser.urlencoded({ extended: false }));  
app.use(cookieParser());

// Initialize Forest Admin  
(async () =\> {  
try {  
await forestadmin(app);  
} catch (error) {  
console.error(‘Failed to setup Forest Admin:’, error);  
process.exit(1);  
}  
})();

// Protect `/forest` routes  
app.use(‘/forest’, (req, res, next) =\> {  
const PUBLIC\_ROUTES = [‘/authentication’];  
if (PUBLIC\_ROUTES.some((route) =\> req.url.startsWith(route))) {  
return next();  
}  
if (!req.user) {  
return res.status(401).send(‘Unauthorized’);  
}  
next();  
});

// Static files  
app.use(express.static(path.join(\_\_dirname, ‘public’)));

module.exports = app;  
```

- Customized the `users` collection with smart actions, smart fields, and smart segments.

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [January 22, 2025, 10:47am UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/2 "2025-01-22T10:47:32Z")

</div>

Hello,  
Do you always encounter the issue?  
Could you provide a network logs from your ForestAdmin app to try to understand the issue?  
Could you provide the entire logs from you agent please ?

Thank you 🙏,  
Best regards,  
Alban

---

<div class="post-metadata">

**Author:** ![ilyas](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@ilyas](https://community.forestadmin.com/u/ilyas)\
**Post date:** [January 22, 2025, 2:12pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/3 "2025-01-22T14:12:55Z")

</div>

![Capture d’écran 2025-01-22 151104](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/9/9c8ac8b03053f9de2def2cad2dbb8726a6578680.png)  
 ![Capture d’écran 2025-01-22 151008](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/2/2832c2934533ea44f3d953aafd3831401a8c9c08.png)

I refreshed multiple times, and the authentication post request stays pending and nothing happens

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [January 22, 2025, 2:47pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/4 "2025-01-22T14:47:53Z")

</div>

> [@ilyas](#):
>
> if (process.env.CORS\_ORIGINS) {  
> allowedOrigins = allowedOrigins.concat(process.env.CORS\_ORIGINS.split(‘,’));  
> }

Could you remove this block in your code and retry your case please? I suspect a CORS issue, you probably override your default configuration with your CORS\_ORIGINS in your env variables.

---

<div class="post-metadata">

**Author:** ![ilyas](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@ilyas](https://community.forestadmin.com/u/ilyas)\
**Post date:** [January 22, 2025, 2:59pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/5 "2025-01-22T14:59:29Z")

</div>

i tried that but it doesn’t work

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [January 22, 2025, 3:07pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/6 "2025-01-22T15:07:17Z")

</div>

Did you try to remove the entire code related to the CORS to understand if it causes this issue?

---

<div class="post-metadata">

**Author:** ![ilyas](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@ilyas](https://community.forestadmin.com/u/ilyas)\
**Post date:** [January 22, 2025, 3:36pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/7 "2025-01-22T15:36:09Z")

</div>

i did, and its still the same behavior,

and when i remove the CORS\_ORIGINS from .env i get a cors error :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/165639d3b49b32ced0be1ba1674859893cccf031.png)

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [January 22, 2025, 3:55pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/8 "2025-01-22T15:55:19Z")

</div>

Could you replace the origin property by this one and retry:

> origin: “\*”

If it works, your `allowedOrigins` variables are probably wrongs.

---

<div class="post-metadata">

**Author:** ![ilyas](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@ilyas](https://community.forestadmin.com/u/ilyas)\
**Post date:** [January 22, 2025, 5:52pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/9 "2025-01-22T17:52:04Z")

</div>

now i get this :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/0fa5f584340c1e7b8ca1a91a47eae8b023fc7cac.png)

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [January 23, 2025, 7:55am UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/10 "2025-01-23T07:55:48Z")

</div>

You could add this property to disable credentials:

> credentials: false

In production, I recommend to use a CORS configuration. These tips are only intended to help you understand which part is not working.

---

<div class="post-metadata">

**Author:** ![ilyas](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@ilyas](https://community.forestadmin.com/u/ilyas)\
**Post date:** [January 23, 2025, 2:41pm UTC](https://community.forestadmin.com/t/authentication-loading-indefinitely-and-no-error-message-appears/7771/11 "2025-01-23T14:41:13Z")

</div>

i got help from this post :

> [@Unclear migration process from forest-express-sequelize to @forestadmin/agent](https://community.forestadmin.com/t/unclear-migration-process-from-forest-express-sequelize-to-forestadmin-agent/7571/3):
>
> Hi @dogan.ay, Thank you for your quick response and help. I have indeed already gone through the migration guide documentation - that’s how I migrated all of the smart actions, etc. The reason I’m confused is because I can’t see any information in the documentation about the specific issues I asked about, namely the public routes and authentication. It’s good to know that this has been abstracted and is now handled by the agent. So to break it down, based on the quick start page you shared wit…

I was trying to migrate the authentication too, when i should have deleted all the code related to the authentication since the agent takes care of it
