cdlciddit
asked on
How to get passport to work with mongoDB
Hello. I am working on a node application. I'm trying to use Passport for the log in. I found an example online of what I want to do. However I cannot get it to work. I am running into an issue with my routes. I get a compiler error that I have not seen before. I tried to attached the project to this question, but it won't accept zip files so I will just attach my index.js and AuthController.js. This is the error I get on index.js when it tries to do my first route.
index.js:349
throw new mongoose.Error.OverwriteMo delError(n ame);
OverwriteModelError: Cannot overwrite `User` model once compiled.
at MongooseError.OverwriteMod elError (C:\Users\ernest\Documents \coding bootcamp\code\Passport MongoDB\node-passport-auth \node_modu les\mongoo se\lib\err or\overwri teModel.js :18:11)
at Mongoose.model (C:\Users\ernest\Documents \coding bootcamp\code\Passport MongoDB\node-passport-auth \node_modu les\mongoo se\lib\ind ex.js:349: 13)
at Object.<anonymous> (C:\Users\ernest\Documents \coding bootcamp\code\Passport MongoDB\node-passport-auth \models\us er.js:12:2 7)
at Module._compile (module.js:570:32)
at Object.Module._extensions. .js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\ernest\Documents \coding bootcamp\code\Passport MongoDB\node-passport-auth \app.js:21 :12)
at Module._compile (module.js:570:32)
at Object.Module._extensions. .js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_module s\\npm\\bi n\\npm-cli .js" "start"
npm ERR! node v6.11.0
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! node-passport-auth@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-passport-auth@0.0.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-passport-auth package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs node-passport-auth
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls node-passport-auth
npm ERR! There is likely additional logging output above.
index.js
AuthController.js
var auth = require("../controllers/AuthController.js");
// restrict index for logged in user only
router.get('/', auth.home);
I get this error: index.js:349
throw new mongoose.Error.OverwriteMo
OverwriteModelError: Cannot overwrite `User` model once compiled.
at MongooseError.OverwriteMod
at Mongoose.model (C:\Users\ernest\Documents
at Object.<anonymous> (C:\Users\ernest\Documents
at Module._compile (module.js:570:32)
at Object.Module._extensions.
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\ernest\Documents
at Module._compile (module.js:570:32)
at Object.Module._extensions.
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_module
npm ERR! node v6.11.0
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! node-passport-auth@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-passport-auth@0.0.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-passport-auth package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs node-passport-auth
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls node-passport-auth
npm ERR! There is likely additional logging output above.
index.js
AuthController.js
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER