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
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










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.