Chapter 18: Token authentication

After typing all the changes in the code, on RESTed when I’m sending the request to: http://localhost:8080/api/users/login

I’m getting the error:

Server starting on http://localhost:8080
[ ERROR ] FluentError.invalidID: Could not convert parameter login to type UUID (Model.swift:457)

I’ve checked the code changes but I don’t see any difference, I don’t know where could be the problem

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

@bayomx could you show your login handler code and how you’re registering it in the boot function? That’s a weird error!


func loginHandler(_ req: Request) throws → Future {
let user = try req.requireAuthenticated(User.self)
let token = try Token.generate(for: user)

  return req)


func boot(router: Router) throws {
let usersRoute = router.grouped(“api”, “users”), use: createHandler)
  usersRoute.get(use: getAllHandler)
  usersRoute.get(User.parameter, use: getHandler)
  usersRoute.get(User.parameter, "acronyms", use: getAcronymsHandler)

  let basicAuthMiddleware = User.basicAuthMiddleware(using: BCryptDigest())
  let basicAuthGroup = usersRoute.grouped(basicAuthMiddleware)"login", use: loginHandler)


That looks sensible! How are you sending the request in Rested?

sorry, it was my mistake, I was sending the request as GET instead of POST, it’s working fine now
correct incorrect

:tada: glad you got it working!