I’ve been reading Ueberauth guides and I found the top 2 articles (on medium.com) use this function:
defp insert_or_update_user(changeset) do
case Repo.get_by(User, email: changeset.changes.email) do
nil ->
Repo.insert(changeset)
user ->
{:ok, user}
end
end
Now from what I see, this function is either inserting or simply returning an existing user from the database. There is no actual update happening (i.e. the OAuth’s tokens / new data is not being updated on the existing user)
Am I missing something? This seems more relevant to me:
defp insert_or_update_user(params) do
case Repo.get_by(User, email: params.email) do
nil ->
# Insert a new user
Repo.insert User.changeset(%User{}, params)
user ->
# Update the user data
Repo.update User.changeset(user, params)
end
end
(https://medium.brianemory.com/elixir-phoenix-creating-an-app-part-4-using-google-überauth-e7d2ed1a3541)
(https://medium.com/@rrugamba/setting-up-google-oauth-in-phoenix-9167595f5fb7)