Here's the error that I'm getting:
Wrong type. The password and hash need to be strings.
It's pointing to this line in my web/controllers/auth.ex file:
user && checkpw(given_pass, user.password_hash) ->
which is a line in this function:
def login_by_email_and_pass(conn, email, given_pass, opts) do
repo = Keyword.fetch!(opts, :repo)
user = repo.get_by(Qlc.User, email: email)
cond do
user && checkpw(given_pass, user.password_hash) ->
{:ok, login(conn, user)}
user ->
{:error, :unauthorized, conn}
true ->
dummy_checkpw()
{:error, :not_found, conn}
end
end
This function is called from the SessionController module's create action:
def create(conn, %{"session" => %{"email" => email, "password" => pass}}) do
case Qlc.Auth.login_by_email_and_pass(conn, email, pass, repo: Repo) do
{:ok, conn} ->
conn
|> put_flash(:info, "Welcome back!")
|> redirect(to: page_path(conn, :index))
{:error, _reason, conn} ->
conn
|> put_flash(:error, "Invalid email/password combination")
|> render("new.html")
end
end
How can I solve this error? I'm not sure why the password and hash are not strings and/or how I can fix this.