Advertisement
Guest User

Untitled

a guest
Oct 7th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. var mongoose = require('mongoose');
  2. var Schema = mongoose.Schema;
  3. var passportLocalMongoose = require('passport-local-mongoose');
  4.  
  5. var Account = new Schema({
  6. username: {
  7. type: String,
  8. required: true
  9. },
  10. password: {
  11. type: String
  12. }
  13. });
  14.  
  15. Account.plugin(passportLocalMongoose);
  16. module.exports = mongoose.model('Account', Account);
  17.  
  18. router.post('/register', function (req, res) {
  19. var username = req.body.username;
  20. var password = req.body.password;
  21.  
  22. Account.register(new Account({username: username}), password, function (err, account) {
  23. ...
  24. });
  25. });
  26.  
  27. import {
  28. model,
  29. PassportLocalDocument,
  30. PassportLocalSchema,
  31. PassportLocalModel,
  32. Schema
  33. } from 'mongoose';
  34.  
  35. import * as passportLocalMongoose from 'passport-local-mongoose';
  36.  
  37. var accountSchema: PassportLocalSchema = new Schema({
  38. username: {
  39. type: String,
  40. required: true
  41. },
  42. password: {
  43. type: String
  44. }
  45. });
  46.  
  47. accountSchema.plugin(passportLocalMongoose);
  48.  
  49. interface IAccount extends PassportLocalDocument {
  50. username: string;
  51. }
  52.  
  53. interface IAccountModel<T extends PassportLocalDocument> extends PassportLocalModel<T> {
  54.  
  55. }
  56.  
  57.  
  58. var Account: IAccountModel<IAccount> = model<IAccount, IAccountModel<IAccount>>('Account', accountSchema);
  59.  
  60. export default Account;
  61.  
  62. indexRouter.post('/register', (req: AuthRequest, res: Response, next: NextFunction)=> {
  63. let username = req.body.username;
  64. let password = req.body.password;
  65.  
  66. Account.register(new Account({username: username}), password, (err: any)=> {
  67. ...
  68. });
  69. });
  70.  
  71. Error:(24, 22) TS2345: Argument of type 'IAccount' is not assignable to parameter of type 'PassportLocalModel<IAccount>'.
  72. Types of property 'authenticate' are incompatible.
  73. Type '(password: string, cb: (err: any, res: any, error: any) => void) => void' is not assignable to type '() => (username: string, password: string, cb: (err: any, res: IAccount, error: any) => void) => ...'.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement