After login on heroku it's still redirect to login page
Describe the bug I deploy on heroku, i access to login page and login, but it's still redirect to login page instead of to homepage. But in local, it works normally
Installed libraries and their versions
my dependencies
- "@adminjs/express": "^5.0.1",
- "@adminjs/mongoose": "^3.0.1",
- "adminjs": "^6.5.0",
Can anyone help me???
up!
Have you followed our documentation for Express and set up a session store for your remote environment? You're being redirected back because the session cookie is not created which can be due to many reasons but I'd start with setting up the session store.
AdminJS.registerAdapter({ Resource: AdminJSMongoose.Resource, Database: AdminJSMongoose.Database, });
const admin = new AdminJS(Admin);
const sessionStore = new MongoDBStore({ uri: mongoUri, collection: "sessions", });
const adminRouter = AdminJSExpress.buildAuthenticatedRouter( admin, { authenticate, cookieName: "adminjs", cookiePassword: "sessionsecret", }, null, { store: sessionStore, resave: true, saveUninitialized: true, secret: "sessionsecret", cookie: { httpOnly: process.env.NODE_ENV === "production", secure: process.env.NODE_ENV === "production", }, name: "adminjs", } );
**// This is my code, i follow step by step, i store sessions in mongoDB, but it still not work
Is your NODE_ENV=production? Heroku app's url is secure so:
cookie: {
httpOnly: process.env.NODE_ENV === "production",
secure: process.env.NODE_ENV === "production",
},
secure flag must be set to true for the cookie to be created
when i set config var on heroku NODE_ENV='production' and set like this cookie: { httpOnly: process.env.NODE_ENV === "production", secure: true, },
it's still not work, and i check cookie not create on heroku but in local it is still normal
Do you use herokuapp domain or a custom one?