Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Created October 20, 2016 20:58
Show Gist options
  • Save bnhansn/44dc1b3106ea35e06425e0a57740d1d1 to your computer and use it in GitHub Desktop.
Save bnhansn/44dc1b3106ea35e06425e0a57740d1d1 to your computer and use it in GitHub Desktop.
defmodule Sling.GuardianSerializer do
@behaviour Guardian.Serializer
alias Sling.Repo
alias Sling.User
def for_token(user = %User{}), do: {:ok, "User:#{user.id}"}
def for_token(_), do: {:error, "Unknown resource type"}
def from_token("User:" <> id), do: {:ok, Repo.get(User, String.to_integer(id))}
def from_token(_), do: {:error, "Unknown resource type"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment