maz
Hi all, I’m not clear why this function is not returning a value:
def confirm_email!(user = %User{email_confirmed: false}) do
confirm = User.changeset_confirm_email(user, true)
case Repo.update(confirm) do
# Updated with success
{:ok, updated_user} ->
Logger.debug("update success")
{:ok, updated_user}
{:error, _, reason, _} ->
Logger.debug("update error")
Logger.error(reason)
{:error, reason}
end
Logger.debug("end of confirm_email")
end
I see in the log:
[debug] QUERY OK db=7.2ms queue=5.3ms idle=633.5ms
UPDATE "users" SET "email_confirmation_token" = $1, "email_confirmed" = $2, "updated_at" = $3 WHERE "id" = $4 [nil, true, ~U[2020-08-19 02:18:18Z], 1]
[debug] update success
[debug] end of confirm_email
[info] Sent 204 in 85ms
The side-effect is that the page is not routing from the caller:
def confirm_email(conn, %{"token" => token}) do
Logger.debug("confirm_email token: #{token}")
case Accounts.confirm_email!(token) do
{:ok, updated_user} ->
Logger.debug("updated_user: #{updated_user}")
conn
|> Guardian.Plug.sign_in(updated_user)
|> put_flash(:info, gettext("Welcome %{user_name}!", user_name: updated_user.name))
|> redirect(to: Routes.page_path(conn, :index))
{:error, reason} ->
Logger.debug("error reason: #{reason}")
json(put_status(conn, 404), %{error: "invalid_token"})
end
end
It’s just not clear to me why it doesn’t appear to be returning the tuple I expect.
Michael
Trending in Chat/Questions
HI
Its matin and new in Elixir (my pleasure)
im creator of Land of Rust
want to build something like land of rust but for Elixir. ne...
New
Other Trending Topics
Hey everyone,
I’ve been working on something for the past while and finally published it, so I wanted to share.
It’s called Infusion. Y...
New
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
cmkarlsson
You are returning the result of the last
Logger.debugexpression which is:okIf you really wanted the “end of confirm_email” logging you need to return the result after.
mindok
The last statement in your function is
Logger.debugcall, so it’s return will be your return valuemaz
I updated it as you suggested and there was no change.
cmkarlsson
And you have recompiled and reloaded the module?
Can you try running your
Accounts.confirm_email!/1function in the repl and make sure it returns what it is supposed to?valehelle
That is weird, you should at least hit one of the case or get an error.
Do you have any other confirm_email function that is calling Accounts.confirm_email()?
maz
When running in the repl it seems to return the result:
I should mention there are two other confirm_email() functions, here are them all:
[EDIT]
adding referred functions(User):
maz
That might be the case, see my response to @cmkarlsson
valehelle
The confirm_email function you showed is under Accounts. What about the confirm_email function under the controller?
maz
I deleted my response by mistake.
You were right, the root problem was the router. I was calling
get("/confirm_email/:token", UserController, :confirm_email)# for json apiand not:
get("/confirm_email/:token", SignupController, :confirm_email)SignupController:
Works fine. Thanks for the help. Guilty of programming while tired.
Leaving this here so others might benefit.