Home > other >  KeystoneJS Configuration : Error Please provide a cookie secret value for session encryption
KeystoneJS Configuration : Error Please provide a cookie secret value for session encryption

Time:11-22

KeystoneJS Configuration : Error Please provide a cookie secret value for session encryption. Version:4

I just created using keystone.js v4. And It's working for connecting to MongoDB Cloud Atlas. I was trying to deploy on Heroku. But It's the error.

Here are the error details of the Heroku log:

2021-11-18T15:53:06.601525 00:00 app[web.1]:
2021-11-18T15:53:06.601539 00:00 app[web.1]: KeystoneJS Configuration Error:
2021-11-18T15:53:06.601540 00:00 app[web.1]:
2021-11-18T15:53:06.601540 00:00 app[web.1]: Please provide a `cookie secret` value for session encryption.
2021-11-18T15:53:06.601541 00:00 app[web.1]:
2021-11-18T15:53:06.730461 00:00 heroku[web.1]: Process exited with status 1
2021-11-18T15:53:06.742844 00:00 heroku[web.1]: State changed from starting to crashed

Keystone.js File:

require("dotenv").config();

// Require keystone
var keystone = require("keystone");
var handlebars = require("express-handlebars");

keystone.init({
    name: "ABC",
    brand: "XYZ",

    sass: "public",
    static: "public",
    favicon: "public/favicon.ico",
    views: "templates/views",
    "view engine": ".hbs",
    "cloudinary config": process.env.CLOUDINARY_URL,
    "cookie secret": process.env.COOKIE_SECRET,
    "custom engine": handlebars.create({
        layoutsDir: "templates/views/layouts",
        partialsDir: "templates/views/partials",
        defaultLayout: "default",
        helpers: new require("./templates/views/helpers")(),
        extname: ".hbs",
    }).engine,

    "auto update": true,
    session: true,
    auth: true,
    "user model": "User",
});

// Load your project's Models
keystone.import("models");

// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set("locals", {
    _: require("lodash"),
    env: keystone.get("env"),
    utils: keystone.utils,
    editable: keystone.content.editable,
});

// Load your project's Routes
keystone.set("routes", require("./routes"));

// Configure the navigation bar in Keystone's Admin UI
keystone.set("nav", {
    posts: ["posts", "post-categories"],
    galleries: "galleries",
    enquiries: "enquiries",
    users: "users",
});

// Start Keystone to connect to your database and initialize the webserver

keystone.start();

//CLOUD SERVER DATABASE
const mongoose = require("mongoose");
mongoose.connect(process.env.MONGO_URI, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
});

Please help me How to fix it?

CodePudding user response:

Have you set a value for the COOKIE_SECRET variable in the Heroku Dashboard? The error you're getting indicates it's undefined or blank.

Heroku calls these "config vars", see the docs.

  • Related