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
Author of Craft GraphQL APIs in Elixir with Absinthe
Most Liked
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.
1
Hermanverschooten
Last Post!
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
0
Popular in Questions
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
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
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
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
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
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
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
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
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
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
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
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
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
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









