Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. if (token) {
  2. try {
  3. var decoded = jsonwebtoken.verify(token, jwt_key);
  4. req.user = decoded.user;///
  5. console.log(req.user._id);// i get id here and from this id i can find user in database
  6. UserSchema.findOne({
  7. _id: req.user._id
  8. })///this query failed finding result
  9. .exec(function(err, result) {
  10. if (err) {
  11. console.log(err);//error gets output in the console.
  12. res.status(500);
  13. return res.json({
  14. result: err
  15. });
  16. }
  17. if (result) {
  18. return next();
  19. } else {
  20. res.status(400);
  21. return res.json({
  22. message: "The user does not exists"
  23. });
  24. }
  25. });
  26.  
  27. } catch (err) {
  28. res.status(403);
  29. res.json({
  30. message: "Invalid Token"
  31. });
  32. }
  33. } else {
  34. res.status(401);
  35. res.json({
  36. message: "No token provided"
  37. });
  38. }
  39.  
  40. { [CastError: Cast to ObjectId failed for value "5875d76e1df97635623061c5" at path "_id" for model "User"]
  41. message: 'Cast to ObjectId failed for value "5875d76e1df97635623061c5" at path "_id" for model "User"',
  42. name: 'CastError',
  43. stringValue: '"5875d76e1df97635623061c5"',
  44. kind: 'ObjectId',
  45. value: '5875d76e1df97635623061c5',
  46. path: '_id',
  47. reason: undefined,
  48. model:
  49. { [Function: model]
  50. hooks: Kareem { _pres: {}, _posts: {} },
  51. base:
  52. Mongoose {
  53. connections: [Object],
  54. plugins: [],
  55. models: [Object],
  56. modelSchemas: [Object],
  57. options: [Object] },
  58. modelName: 'User',
  59. model: [Function: model],
  60. db:
  61. NativeConnection {
  62. base: [Object],
  63. collections: [Object],
  64. models: [Object],
  65. config: [Object],
  66. replica: false,
  67. hosts: null,
  68. host: 'localhost',
  69. port: 27017,
  70. user: undefined,
  71. pass: undefined,
  72. name: 'myschoolbus_demo',
  73. options: [Object],
  74. otherDbs: [],
  75. _readyState: 1,
  76. _closeCalled: false,
  77. _hasOpened: true,
  78. _listening: false,
  79. db: [Object] },
  80. discriminators: undefined,
  81. schema:
  82. Schema {
  83. obj: [Object],
  84. paths: [Object],
  85. subpaths: {},
  86. virtuals: [Object],
  87. singleNestedPaths: {},
  88. nested: [Object],
  89. inherits: {},
  90. callQueue: [Object],
  91. _indexes: [],
  92. methods: [Object],
  93. statics: {},
  94. tree: [Object],
  95. _requiredpaths: undefined,
  96. discriminatorMapping: undefined,
  97. _indexedpaths: undefined,
  98. query: {},
  99. childSchemas: [],
  100. s: [Object],
  101. options: [Object],
  102. '$globalPluginsApplied': true },
  103. collection:
  104. NativeCollection {
  105. collection: [Object],
  106. opts: [Object],
  107. name: 'users',
  108. collectionName: 'users',
  109. conn: [Object],
  110. queue: [],
  111. buffer: false,
  112. emitter: [Object] },
  113. Query: { [Function] base: [Object] },
  114. '$__insertMany': [Function],
  115. insertMany: [Function] } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement