HTTP client for the ClerkJS sdk. https://clerk.com/docs/reference/backend-api
If available in Hex, the package can be installed
by adding clerk to your list of dependencies in mix.exs:
def deps do
[
{:clerk, "~> 1.2.0"}
]
endOnce the dependency is installed you can add your clerk domain and secret key to the config, the clerk module to the application tree, and then you can make API calls.
config :clerk,
domain: "example.clerk.accounts.dev",
secret_key: System.get_env("CLERK_API_KEY") || raise("CLERK_API_KEY environment variable is missing.")You can also export the secret key via bash. This is useful for local development.
export CLERK_API_KEY=sk_test_your-secret-keyIf you want to use a .env file, can use dotenv to load the config from a .env file. This is useful for local development. In production, you should set the environment variables directly into the server.
# .env
CLERK_API_KEY=sk_somekeyabc123
children = [
...
{Clerk, Application.get_all_env(:clerk)},
...
]and then
iex> Clerk.User.list()
{:ok,
[
%{
"id" => "user_abcd12345",
"locked" => false,
"has_image" => true,
"banned" => false,
...
}
]
}You can also use the Clerk.AuthenticationPlug to automatically load the clerk session and user
in plug based elixir applications. i.e. (in phoenix):
pipeline :api do
plug :accepts, ["json"]
plug :fetch_session
plug Clerk.AuthenticationPlug
endwill place a current_user object in conn.assigns
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/clerk.