Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (token) {
- try {
- var decoded = jsonwebtoken.verify(token, jwt_key);
- req.user = decoded.user;///
- console.log(req.user._id);// i get id here and from this id i can find user in database
- UserSchema.findOne({
- _id: req.user._id
- })///this query failed finding result
- .exec(function(err, result) {
- if (err) {
- console.log(err);//error gets output in the console.
- res.status(500);
- return res.json({
- result: err
- });
- }
- if (result) {
- return next();
- } else {
- res.status(400);
- return res.json({
- message: "The user does not exists"
- });
- }
- });
- } catch (err) {
- res.status(403);
- res.json({
- message: "Invalid Token"
- });
- }
- } else {
- res.status(401);
- res.json({
- message: "No token provided"
- });
- }
- { [CastError: Cast to ObjectId failed for value "5875d76e1df97635623061c5" at path "_id" for model "User"]
- message: 'Cast to ObjectId failed for value "5875d76e1df97635623061c5" at path "_id" for model "User"',
- name: 'CastError',
- stringValue: '"5875d76e1df97635623061c5"',
- kind: 'ObjectId',
- value: '5875d76e1df97635623061c5',
- path: '_id',
- reason: undefined,
- model:
- { [Function: model]
- hooks: Kareem { _pres: {}, _posts: {} },
- base:
- Mongoose {
- connections: [Object],
- plugins: [],
- models: [Object],
- modelSchemas: [Object],
- options: [Object] },
- modelName: 'User',
- model: [Function: model],
- db:
- NativeConnection {
- base: [Object],
- collections: [Object],
- models: [Object],
- config: [Object],
- replica: false,
- hosts: null,
- host: 'localhost',
- port: 27017,
- user: undefined,
- pass: undefined,
- name: 'myschoolbus_demo',
- options: [Object],
- otherDbs: [],
- _readyState: 1,
- _closeCalled: false,
- _hasOpened: true,
- _listening: false,
- db: [Object] },
- discriminators: undefined,
- schema:
- Schema {
- obj: [Object],
- paths: [Object],
- subpaths: {},
- virtuals: [Object],
- singleNestedPaths: {},
- nested: [Object],
- inherits: {},
- callQueue: [Object],
- _indexes: [],
- methods: [Object],
- statics: {},
- tree: [Object],
- _requiredpaths: undefined,
- discriminatorMapping: undefined,
- _indexedpaths: undefined,
- query: {},
- childSchemas: [],
- s: [Object],
- options: [Object],
- '$globalPluginsApplied': true },
- collection:
- NativeCollection {
- collection: [Object],
- opts: [Object],
- name: 'users',
- collectionName: 'users',
- conn: [Object],
- queue: [],
- buffer: false,
- emitter: [Object] },
- Query: { [Function] base: [Object] },
- '$__insertMany': [Function],
- insertMany: [Function] } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement