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

First Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Welcome! What version of Joken are you using? What docs are you reading?

Most Liked

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?

Last Post!

victorolinasc

victorolinasc

@SkyFlyOne here is one working example:

# Without a module token
signer = Joken.Signer.create("HS256", "secret")
Joken.generate_and_sign(%{}, %{}, signer) # => will generate an empty token
Joken.generate_and_sign(%{}, %{"user_id" => "some_id"}, signer) # with a claim

# With a module token
defmodule ApiToken do
  use Joken.Config
end
ApiToken.generate_and_sign(%{}, signer) # will use defult config
ApiToken.generate_and_sign(%{"user_id" => "someid"}, signer) # will add extra claims

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement