adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

After login on heroku it's still redirect to login page

Open Dat10496 opened this issue 3 years ago • 6 comments

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???

Dat10496 avatar Nov 09 '22 08:11 Dat10496

up!

Dat10496 avatar Nov 14 '22 04:11 Dat10496

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.

dziraf avatar Nov 14 '22 07:11 dziraf

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

Dat10496 avatar Nov 14 '22 12:11 Dat10496

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

dziraf avatar Nov 14 '22 12:11 dziraf

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

Dat10496 avatar Nov 16 '22 07:11 Dat10496

Do you use herokuapp domain or a custom one?

dziraf avatar Nov 29 '22 14:11 dziraf