Hi,
I am trying to learn Elixir by reading articles and code.
I cam across this code, which I am not able to understand.
It is taken from here: https://github.com/ueberauth/guardian
defmodule MyApp.Guardian do
use Guardian, otp_app: :my_app
def subject_for_token(resource, _claims) do
sub = to_string(resource.id)
{:ok, sub}
end
def subject_for_token(_, _) do
{:error, :reason_for_error}
end
def resource_from_claims(claims) do
id = claims["sub"]
resource = MyApp.get_resource_by_id(id)
{:ok, resource}
end
def resource_from_claims(_claims) do
{:error, :reason_for_error}
end
end
The first subject_for_token function should pattern match any call with 2 parameters. So, why do we need the other one with underscores?
Similarly, why do we need second resource_from_claims function.
Thanks!