Packages

Adds helpful extras to Guardian like default mailer support, as well as out of the box controllers and routes

Current section

Files

Jump to
sentinel lib sentinel serializers guardian_serializer.ex
Raw

lib/sentinel/serializers/guardian_serializer.ex

defmodule Sentinel.GuardianSerializer do
@moduledoc """
Serializer for Guardian. More information available at https://github.com/ueberauth/guardian
"""
@behaviour Guardian.Serializer
alias Sentinel.Config
alias Sentinel.UserHelper
@doc """
Serializes user for a token
"""
def for_token(user) when is_map(user), do: {:ok, "User:#{user.id}"}
def for_token(_), do: {:error, "Unknown resource type"}
@doc """
Serializes use from a token
"""
def from_token("User:" <> id), do: {:ok, Config.repo.get(UserHelper.model, id)}
def from_token(_), do: {:error, "Unknown resource type"}
end