Reem
Reem

Reputation: 31

No exact matches in call to instance method 'filter' in Vapor

I'm facing an error regarding 'filter' function [Fluent's query API | Vapor].

I read the documentation that´s provided by Vapor for this case and it seems the syntax is fine. Hence I've no idea where the exact issue is located.

Screenshot Link

        func login(req: Request) throws -> EventLoopFuture<String>
        {
            let userToLogin = try
                req.content.decode(UserLogin.self)
            print("user to login \(userToLogin)")
            
            //Get user from DB
            return User.query(on: req.db)
                .filter( \.$email == userToLogin.email)
                .first()
                .unwrap(or: Abort(.notFound))
                .flatMapThrowing { dbUser in 
                    let verified = try dbUser.verify(password: userToLogin.password)
                    print("attempt verify password \(verified)")
                    if verified == false {
                        throw Abort(.unauthorized)
                    }
                    
                    req.auth.login(dbUser)
                    let user = try req.auth.require(User.self)
                    return try user.generateToken(req.application)
                }
        }

Upvotes: 1

Views: 435

Answers (1)

cora
cora

Reputation: 2102

The problem is not with filter, but with == that needs to be overloaded.

Make sure you have

import Fluent
import Vapor

in you file.

Upvotes: 3

Related Questions