Gamend.Accounts.Identities (gamend_core v1.0.1296)

Copy Markdown View Source

How a person signs in without a password — Discord, Apple, Google, Facebook, GitHub, Steam or a device id — and linking those identities to an existing account or removing them from one.

Split out of Gamend.Accounts, which still exposes every function here under the same name.

Summary

Functions

Attach a device_id to an existing user record. Returns {:ok, user} or {:error, changeset} if the device_id is already used.

Finds a user by Apple ID or creates a new user from OAuth data.

Finds or creates a user associated with the given device_id.

Finds a user by Discord ID or creates a new user from OAuth data.

Finds a user by Facebook ID or creates a new user from OAuth data.

Finds a user by GitHub ID or creates a new user from OAuth data.

Finds a user by Google ID or creates a new user from OAuth data.

Finds a user by Steam ID or creates a new user from Steam OpenID data.

Link an OAuth provider to an existing user account. Updates the user via the provider's oauth changeset while being careful not to overwrite existing email or avatars.

Link a device_id to an existing user account. This allows the user to authenticate using the device_id in addition to their OAuth providers.

Unlink the device_id from a user's account.

Unlink an OAuth provider from a user's account.

Functions

attach_device_to_user(user, device_id)

@spec attach_device_to_user(Gamend.Accounts.User.t(), String.t()) ::
  {:ok, Gamend.Accounts.User.t()} | {:error, Ecto.Changeset.t()}

Attach a device_id to an existing user record. Returns {:ok, user} or {:error, changeset} if the device_id is already used.

find_or_create_from_apple(attrs)

@spec find_or_create_from_apple(map()) ::
  {:ok, Gamend.Accounts.User.t()} | {:error, Ecto.Changeset.t() | term()}

Finds a user by Apple ID or creates a new user from OAuth data.

Examples

iex> find_or_create_from_apple(%{apple_id: "123", email: "user@example.com"})
{:ok, %User{}}

find_or_create_from_device(device_id, attrs \\ %{})

@spec find_or_create_from_device(String.t(), map()) ::
  {:ok, Gamend.Accounts.User.t()}
  | {:error, :disabled | Ecto.Changeset.t() | term()}

Finds or creates a user associated with the given device_id.

If a user already exists with the device_id we return it. Otherwise we create an anonymous confirmed user and attach the device_id.

find_or_create_from_discord(attrs)

@spec find_or_create_from_discord(map()) ::
  {:ok, Gamend.Accounts.User.t()} | {:error, Ecto.Changeset.t() | term()}

Finds a user by Discord ID or creates a new user from OAuth data.

Examples

iex> find_or_create_from_discord(%{discord_id: "123", email: "user@example.com"})
{:ok, %User{}}

find_or_create_from_facebook(attrs)

@spec find_or_create_from_facebook(map()) ::
  {:ok, Gamend.Accounts.User.t()} | {:error, Ecto.Changeset.t() | term()}

Finds a user by Facebook ID or creates a new user from OAuth data.

Examples

iex> find_or_create_from_facebook(%{facebook_id: "123", email: "user@example.com"})
{:ok, %User{}}

find_or_create_from_github(attrs)

@spec find_or_create_from_github(map()) ::
  {:ok, Gamend.Accounts.User.t()} | {:error, Ecto.Changeset.t() | term()}

Finds a user by GitHub ID or creates a new user from OAuth data.

Examples

iex> find_or_create_from_github(%{github_id: "123", email: "user@example.com"})
{:ok, %User{}}

find_or_create_from_google(attrs)

@spec find_or_create_from_google(map()) ::
  {:ok, Gamend.Accounts.User.t()} | {:error, Ecto.Changeset.t() | term()}

Finds a user by Google ID or creates a new user from OAuth data.

Examples

iex> find_or_create_from_google(%{google_id: "123", email: "user@example.com"})
{:ok, %User{}}

find_or_create_from_steam(attrs)

@spec find_or_create_from_steam(map()) ::
  {:ok, Gamend.Accounts.User.t()} | {:error, Ecto.Changeset.t() | term()}

Finds a user by Steam ID or creates a new user from Steam OpenID data.

Examples

iex> find_or_create_from_steam(%{steam_id: "12345", email: "user@example.com"})
{:ok, %User{}}