Ulrar
Ulrar

Reputation: 983

Exception from Warp: stack overflow when logging in

I'm making a little app for work to handle shared to-do lists, I'm almost done but I'd like to add some very simple authentication. I followed the doc to add hashdb to the scaffolded site (https://github.com/yesodweb/yesod-cookbook/blob/master/cookbook/Using-HashDB-In-a-Scaffolded-Site.md), and it compiles fine, but when I log in with correct username / password (added by hand in the database) I get this :

10/Dec/2016:13:36:02 +0100 [Debug#SQL] SELECT `name`,`password` FROM `user` WHERE `name`=?; [PersistText "Ulrar"]
10/Dec/2016:13:36:08 +0100 [Error#yesod] Exception from Warp: stack overflow @(cstod_GjWCdZJB9K0EGPCbjz5gnP:Application Application.hs:133:15)

Line 133 of Application.hs is this one : $(qLocation >>= liftLoc) That's from the default code.

As you can see my "User" table is pretty simple, I have a primary key on the name and a password, and that's it. The name must be unique, of course. I'll be adding the few user by hand in the database, that'll be more than enough for us.

I tried the query by hand, it returns what you'd expect, and trying to log in with the wrong username / password does "work", it redirects to the login form with an error. Only using the correct username / password couple will give that Exception, and it does seem to load for a while before throwing it after clicking on the button.

I end up on http://localhost:3000/auth/page/hashdb/login with just "Something went wrong" written.

I assume I must have missed something, I'm using the yesod-mysql scaffolded site and I have this in the YesodAuth instance :

authPlugins app = [authHashDB (Just . UniqueUser)]

I removed the getAuthId definition since I had no idea what to put there, the definition from the doc doesn't compile because getAuthIdHashDB isn't exported anymore apparently. Is this my problem ?

Thanks !

Upvotes: 1

Views: 85

Answers (1)

Ulrar
Ulrar

Reputation: 983

Yep, my problem was indeed removing getAuthId ! Solved it by adding this instead :

    authenticate creds = runDB $ do
      x <- getBy $ UniqueUser $ credsIdent creds
      case x of
        Just (Entity uid _) -> return $ Authenticated uid
        Nothing -> return $ UserError InvalidUsernamePass

Upvotes: 1

Related Questions