Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mongoose = require('mongoose');
- var Schema = mongoose.Schema;
- var passportLocalMongoose = require('passport-local-mongoose');
- var Account = new Schema({
- username: {
- type: String,
- required: true
- },
- password: {
- type: String
- }
- });
- Account.plugin(passportLocalMongoose);
- module.exports = mongoose.model('Account', Account);
- router.post('/register', function (req, res) {
- var username = req.body.username;
- var password = req.body.password;
- Account.register(new Account({username: username}), password, function (err, account) {
- ...
- });
- });
- import {
- model,
- PassportLocalDocument,
- PassportLocalSchema,
- PassportLocalModel,
- Schema
- } from 'mongoose';
- import * as passportLocalMongoose from 'passport-local-mongoose';
- var accountSchema: PassportLocalSchema = new Schema({
- username: {
- type: String,
- required: true
- },
- password: {
- type: String
- }
- });
- accountSchema.plugin(passportLocalMongoose);
- interface IAccount extends PassportLocalDocument {
- username: string;
- }
- interface IAccountModel<T extends PassportLocalDocument> extends PassportLocalModel<T> {
- }
- var Account: IAccountModel<IAccount> = model<IAccount, IAccountModel<IAccount>>('Account', accountSchema);
- export default Account;
- indexRouter.post('/register', (req: AuthRequest, res: Response, next: NextFunction)=> {
- let username = req.body.username;
- let password = req.body.password;
- Account.register(new Account({username: username}), password, (err: any)=> {
- ...
- });
- });
- Error:(24, 22) TS2345: Argument of type 'IAccount' is not assignable to parameter of type 'PassportLocalModel<IAccount>'.
- Types of property 'authenticate' are incompatible.
- 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