thank you for spending time looking at this problem.
Firstly, when I test this in localhost:3000 it works, there are no errors and I can seamlessly run my application, encrypt my password and push it to MongoDB.
Then, the problem sets in with Heroku after I do my git commits and push it through. The app does not start and crashes. and comes up with errors that I have scoured the internet for and even those who had problems, and I have completely copied there solutions, still have the same error.
heroko logs --tail (hyper console):
throw new Error('must provide either options.secret or both options.encryptionKey and options.signingKey');
however I do provide these and I like I have said, I have scoured and observed the internet:
.!.dotenv has been installed as a node package!!
My server JS:
require('dotenv').config();
const mongoose = require("mongoose");
const tytyDigitalSchema = new mongoose.Schema({
username: String,
password: String,
email: String,
verified: Boolean
});
var secret = process.env.SOME_LONG_UNGUESSABLE_STRING;
tytyDigitalSchema.plugin(encrypt, { secret: secret , encryptedFields: ['Password']});
const Users = mongoose.model("user", tytyDigitalSchema);
My.env file
SOME_LONG_UNGUESSABLE_STRING=Thisisa32bytebasestring
Lastly, incase it helps, my.gitignore: https://github.com/github/gitignore/blob/main/Node.gitignore
This has solved it: Heroku does not read your.env file as you.gitignore it. Instead in Heroku (application screen), you will see a settings page and a config vars panel, which asks for a key and a value, these fields represent our.env file. So my KEY would have to be:
SOME_LONG_UNGUESSABLE_STRING
and my value would be:
Thisisa32bytebasestring
This will now enable to site to be built correctly and work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.