What is {:error, :secret_not_found}?

I got {:error, :secret_not_found} when I use guardiandb.

What does the error mean?

On what function call exactly?

But probably it means, there was an error while processing your function, reported as “:secret_not_found”.

What exactly the meaning of this is, you have to look up in the documentation of the function that returns this value.

1 Like

I got that error of Guardian.encode_and_sign.

def login(conn, %{"id"=>id, "password"=>plain_text_password}) do
    IO.inspect("LOGIN: " <> plain_text_password)

    |> login_reply(Auth.authenticate_student(id, plain_text_password))

  defp login_reply(conn, {:ok, student}) do
    {:ok, access_token, access_claims, refresh_token, _refresh_claims} = create_token(student |> IO.inspect)
    response = %{
      access_token: access_token,
      refresh_token: refresh_token,
      expires_in: access_claims["exp"]
    render(conn, "login.json", response: response)

defp create_token(student) do
    {:ok, access_token, access_claims} = Guardian.encode_and_sign(student, %{}, [token_type: "access", ttl: {1, :weeks}])
    {:ok, refresh_token, refresh_claims} = Guardian.encode_and_sign(student, %{access_token: access_token}, [token_type: "refresh", ttl: {4, :weeks}])
    {:ok, _a_token} = AuthTokens.after_encode_and_sign(student, access_claims, access_token)
    {:ok, _r_token} = AuthTokens.after_encode_and_sign(student, refresh_claims, refresh_token)
    {:ok, access_token, access_claims, refresh_token, refresh_claims}

I don’t get what occurs in my code exactly…
What should I check first?

As a first disclaminer, let me say you that I do not use guardian or anything related.

According to the documentation, the first argument to Guardian.encode_and_sign/4 should be a module, is student a module?

Also the 3rd argument should be a map, not a keyword list.

So my assumption simply is, that you are missing the first argument to the call, and everything else is off by one, then student would be the resource to encode, which would make sense to me.


I think there is nothing wrong around the arguments of Guardian.encode_and_sign.
I referred this repository though…

Do you have any ideas or I have to show anything else?

Hi @Papillon6814 :slight_smile:
One suggestion: In general, when asking for help, you will get more accurate responses if you give more precise informations about what error occurs in which function, possibly the stack trace, the relevant code, and an indication of what you are trying to achieve.

When debugging, even the most experienced of us will investigate in small steps by looking at the “evidence”, formulating hypotheses, and verifying them: it’s generally not possible to “guess what’s wrong” at a glance, context is very important.

That said, your error seems to indicate, as @NobbZ said, that a secret is missing. I don’t know much about Guardian, but the documentation says that you need to specify a secret key. Could it be that you are missing it, or mis-configuring it? There is this line in the repo you linked, in app_ex/config/config.exs: https://github.com/yujikawa/app_ex/blob/master/config/config.exs#L36 Do you have an equivalent line in your app, using your application name instead of :app_ex?


I could resolve the issue!