Clerk.AuthenticationPlug (Clerk SDK v2.0.0)

Plug for authenticating requests.

Options

  • :session_key - the cookie name to read the session token from. Defaults to "__session".

  • :fetch_user - when true, fetches the full user object from the Clerk Backend API after token verification and assigns it as :current_user. When false, builds :current_user from the JWT claims alone (no network request). Defaults to true.

  • :config - a %Clerk.Config{} for verification and API calls. Defaults to Clerk.config/0. Required when running multiple Clerk tenants in an umbrella app.

Examples

# Fetches user from Clerk API on every request (default)
plug Clerk.AuthenticationPlug

# Skip the API call — use JWT claims only
plug Clerk.AuthenticationPlug, fetch_user: false

# Use an explicit Clerk config (umbrella apps)
plug Clerk.AuthenticationPlug, config: config