SkyFlyOne

SkyFlyOne

Joken problem - (UndefinedFunctionError) function Joken.using/1 is undefined or private

Hello I’m facing some problems using Joken to set up JWT for my backend application. I found no solution. I’ve pasted the code below with the error. I think there is a conflict between the versions of Joker

defmodule ApiElixir.TokenManager do
  use Joken

  @secret "secret"

  defp claims() do
    %{
      "iss" => "api_elixir",
      "exp" => Timex.now() |> Timex.add(Timex.Duration.from_seconds(3600)) |> Timex.to_unix(),
      "aud" => "user"
    }
  end

  def encode() do
    Joken.sign(%{}, @secret, claims())
  end

  def decode(token) do
    case Joken.verify(token, @secret) do
      {:ok, _claims} -> {:ok, "Token valide"}
      {:error, reason} -> {:error, reason}
    end
  end
end

Error :

== Compilation error in file lib/token_manager.ex ==
** (UndefinedFunctionError) function Joken.__using__/1 is undefined or private
    (joken 2.6.0) Joken.__using__([])
    lib/token_manager.ex:2: (module)

Thanks all for the help

Most Liked Responses

victorolinasc

victorolinasc

@SkyFlyOne you should use Joken.Config and not Joken.

The docs also show you better intended ways of using Joken’s API. For instance, when “using” the config, you get some generated implementations of encode/decode and some others.

Hermanverschooten

Hermanverschooten

Have you tried putting the statements inside a function inside your module?

Where Next?

Popular in Questions Top

New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement