Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type issues with SerializeUser #332

Open
CarlosAMendoza opened this issue Jul 21, 2021 · 0 comments
Open

Type issues with SerializeUser #332

CarlosAMendoza opened this issue Jul 21, 2021 · 0 comments

Comments

@CarlosAMendoza
Copy link

I'm trying to use Passportjs, and mongoose for authentication but I am having a hard time getting the correct type with typescript.

Passport.use(UserModel.createStrategy())
Passport.serializeUser(UserModel.serializeUser()) // <---- Error

I get the error:

No overload matches this call.
  Overload 1 of 2, '(fn: (user: User, done: (err: any, id?: any) => void) => void): void', gave the following error.
    Argument of type '(user: PassportLocalModel<User>, cb: (err: any, id?: any) => void) => void' is not assignable to parameter of type '(user: User, done: (err: any, id?: any) => void) => void'.
      Types of parameters 'user' and 'user' are incompatible.
        Type 'User' is missing the following properties from type 'PassportLocalModel<User>': authenticate, serializeUser, deserializeUser, register, and 68 more.
  Overload 2 of 2, '(fn: (req: IncomingMessage, user: User, done: (err: any, id?: unknown) => void) => void): void', gave the following error.
    Argument of type '(user: PassportLocalModel<User>, cb: (err: any, id?: any) => void) => void' is not assignable to parameter of type '(req: IncomingMessage, user: User, done: (err: any, id?: unknown) => void) => void'.
      Types of parameters 'user' and 'req' are incompatible.
        Type 'IncomingMessage' is missing the following properties from type 'PassportLocalModel<User>': authenticate, serializeUser, deserializeUser, register, and 53 more.

This is what my User class looks like:

export interface User extends Document {
  email: String
  password: String
  displayName: String
}

const UserSchema = new Schema(
  {
    username: { type: String, unique: true },
    password: String,
    displayName: String,
    roles: [{ type: String }],
  },
  { timestamps: true }
)

UserSchema.plugin(PassportLocalMongoose)

export const UserModel = model<User>('User', UserSchema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant