Building our create session function

Create is going to be a little trickier to write, but not by too much. One of the first gotchas is that we'll need to update the accounts context to look a user up by their username. Hop over to the accounts context (lib/vocial/accounts/accounts.ex) and add the following function:

  def get_user_by_username(username) do    Repo.get_by(User, username: username)  end

In the case where we don't get any users back, we'll return a nil value, but otherwise we'll assume that we got back a user that we can use to check the encrypted password of! get_by\2 just takes the query (in our case, just any user schema) and the conditions to check by and attempts to return back the appropriate row from the table specified in ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.