IngotWeb.Plugs.RequireAuth (Ingot v0.1.0)

View Source

Plug to require authentication for routes.

Validates the session and assigns current_user to conn. Redirects to login page if authentication fails.

Usage

# In router
pipeline :authenticated do
  plug IngotWeb.Plugs.RequireAuth
end

# With custom redirect
pipeline :authenticated do
  plug IngotWeb.Plugs.RequireAuth, redirect_to: "/login"
end

Assigns

On successful authentication, assigns the following to conn:

  • :current_user - Map containing user_id, email, and roles

Summary

Types

options()

@type options() :: keyword()