basic_signup_allowlist/lib/basic_signup_whitelist.ex
2025-09-16 09:03:12 +00:00

34 lines
1.0 KiB
Elixir

defmodule BasicSignupWhitelist do
import FunCore.BasicSignupWhitelist
@moduledoc """
Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable.
"""
@doc """
Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable.
Rules:
- Returns true if ALLOWED_EMAILS == "*" (all emails allowed)
- Returns true if email matches any entry in the comma-separated list
- Returns false if:
* Environment variable doesn't exist
* Environment variable is empty string
* Email not found in whitelist
## Examples
iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
false
iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
true
"""
def mail_whitelisted(email) do
env_value = System.get_env("SIGNUP_ALLOWLIST_EMAILS")
mail_whitelisted_fun(env_value, email)
end
end