Ecto.Changeset helper functions for inserting or regenerating a 2FA secret.
API-compatible with NioGoogleAuthenticator.Changeset. This module is
automatically compiled when :ecto is available in your project.
Summary
Functions
Adds a secret to an Ecto.Changeset if the target field is currently nil.
Regenerates and replaces the secret on an Ecto.Changeset, regardless of
whether a value already exists.
Functions
@spec add_secret_to_changeset(Ecto.Changeset.t(), atom(), keyword()) :: Ecto.Changeset.t()
Adds a secret to an Ecto.Changeset if the target field is currently nil.
Defaults to :ga_secret for compatibility with nio_google_authenticator.
You may pass a custom field atom as the second argument, and optional
:byte_length in options (default 10).
Examples
user
|> cast(params, [:name, :ga_secret])
|> Ex2FA.Changeset.add_secret_to_changeset()
user
|> cast(params, [:name, :totp_secret])
|> Ex2FA.Changeset.add_secret_to_changeset(:totp_secret, byte_length: 20)
@spec regenerate_secret_in_changeset(Ecto.Changeset.t(), atom(), keyword()) :: Ecto.Changeset.t()
Regenerates and replaces the secret on an Ecto.Changeset, regardless of
whether a value already exists.
Defaults to :ga_secret for compatibility with nio_google_authenticator.