TituxMetal/fullstack-remix-real-world

Invariant error on login

Closed this issue · 0 comments

An error comming from invariant is thrown during login process with existing credentials.

This error is comming from extractFormData function that extracts fields from formData and checks the typeof string on each fields, but for login action there is no username.

extractFormData is an abstraction function that does not consider the fields it should extract.

The best for the moment is to remove this function and extract only the needed fields.

This also introduce a second bug: the username is comming from the database query made with getByEmailWithPassword function that returns the user with the password and the profile, but the return statement at line 52 returns the username comming from formData that is undefined or null and this make Typescript unhappy because we have defined the username field in the AuthSession type.

To fix this just extract the username in a const and check it along with user on line 37.