Chapter 24 Password reset

Hi folks,

I’m trying to debug my password reset function from the book. So far I can get the reset password email sent correctly from SendGrid but when I click the link, I have an automatic error showing up in the leaf . “There was a problem with the form. Ensure you clicked on the full link with the token and your passwords match” which is the error we coded in the book, but I don’t know why its being thrown. The url is when the link is clicked is “http://localhost:8080/resetPassword?+oken=VIJL2QSXSL26NXRFWKLNIRXPXXB7YBCVZM7K2OAD63ESHWOAELSQ”. Is it being thrown because the url is malformed? (token seems to be cut off)

When I continue to reset the password it accepts the new password but then forwards an error JSON with the message “No element found in session with ket ‘ResetPasswordUser’” and the URL is still “http://localhost:8080/resetPassword?+oken=VIJL2QSXSL26NXRFWKLNIRXPXXB7YBCVZM7K2OAD63ESHWOAELSQ

It appears to me that there is a token there. I know this is an Imperial Error being thrown (tracked it down through the spelling error), but I’m not sure where the fix might be?

I have been using chrome for a browser since safari seems to force https on me when using localhost. I also have already run swift package update to get the latest Imperial version.

Any ideas on where I can track this down for a fix?

PS: The password hash in PostgreSQL does not seem to change for the User according to Postico. I assume this is also because of the same error.
Also in Postico I see that there are 4 entries in the ResetPasswordToken table corresponding to the amount of times I’ve tried to reset the password. In the Token table itself though, there are no entries, no data at all in fact.

Edit: I see now that the bearer token is not stored in the database at all. Is this stored in the MemoryKeyedCache session?

@beefycode Do you still have issues with this?

I haven’t found a fix yet.

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

Hi @beefycode, apologies for the delay!

So if the token URL is getting malformed, that certainly points to an error. And the token itself should be stored in the database, so that’s the first thing to look for. If you breakpoint at the point where the token is saved, can you see it failing?

I know, I’m late but maybe that’s for the errata.

The problem is here. In the book there’s a backslash before the “t” of token. I don’t know why it is there but that’s the error. Remove that backslash so the link says “…localhost:8080/resetPassword?token…” instead of “…localhost:8080/resetPassword?\token…”, then it works. Had the same problem.

@pintiboy hmm so I’m guessing that’s there because if you copy the code in the book exactly it escapes the new line, but I can see why that’s confusing! We should clear that up for the next edition!