Sigra.DataExport behaviour (Sigra v0.2.2)

Copy Markdown View Source

Behaviour for exporting user data.

Sigra provides a default implementation that exports auth-related data (user profile, sessions, OAuth identities). Application developers implement this behaviour to add app-specific data.

Usage

defmodule MyApp.DataExport do
  @behaviour Sigra.DataExport

  @impl true
  def export_user_data(user) do
    {:ok, %{
      profile: %{name: user.name, bio: user.bio},
      posts: MyApp.Posts.list_by_user(user.id)
    }}
  end
end

Summary

Callbacks

Export all data associated with the given user.

Functions

Exports Sigra's own auth data for a user.

Callbacks

export_user_data(user)

(since 0.8.0)
@callback export_user_data(user :: struct()) :: {:ok, map()} | {:error, term()}

Export all data associated with the given user.

Returns {:ok, map()} with the exported data or {:error, reason}. The map keys and structure are implementation-defined.

Functions

export_auth_data(repo, user, opts \\ [])

(since 0.8.0)
@spec export_auth_data(module(), struct(), keyword()) :: {:ok, map()}

Exports Sigra's own auth data for a user.

Returns a map with keys: :user, :sessions, :identities. This is always included in exports regardless of the app's implementation.

Options

  • :session_schema - The generated UserSession Ecto schema module.
  • :identity_schema - The generated UserIdentity Ecto schema module.