Created
October 20, 2016 20:58
-
-
Save bnhansn/44dc1b3106ea35e06425e0a57740d1d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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