Hello everyone!
Is there anybody who has experience using Joken 2.0?
I am trying to migrate the following code (v1.5.1) to (v2.0)
The API has changed quite significantly can’t seem to follow thru it
Would love to hear your feedback…
views/session_view.ex
defmodule LibraryApiWeb.SessionView do
use LibraryApiWeb, :view
def render("token.json", user) do
data = %{id: user.id, email: user.email, username: user.username}
jwt = %{data: data, sub: user.id}
|> Joken.token
|> Joken.with_signer(Joken.hs512("SOMESECRETVALUE"))
|> Joken.sign
%{token: jwt.token}
end
end
I tried the following:
defmodule LibraryApiWeb.SessionView do
use LibraryApiWeb, :view
def render("token.json", user) do
data = %{id: user.id, email: user.email, username: user.username}
jwt = %{data: data, sub: user.id}
|> LibraryApi.Token.generate_and_sign(Joken.Signer.create("HS512", "SOMESECRETVALUE"))
%{token: jwt.token}
end
end
But I am getting the following in Postman
{
"errors": [
{
"detail": "Error logging in a user with that email and password",
"status": 401,
"title": "Unauthorized"
}
],
"jsonapi": {
"version": "1.0"
}
}
despite that email being in the database already