IngotWeb.Plugs.RequireRole (Ingot v0.1.0)

View Source

Plug to require specific role for routes.

Checks that the current user has the required role. Must be used after RequireAuth plug.

Usage

# In router
pipeline :admin_required do
  plug IngotWeb.Plugs.RequireAuth
  plug IngotWeb.Plugs.RequireRole, role: :admin
end

# With custom redirect
pipeline :labeler_required do
  plug IngotWeb.Plugs.RequireAuth
  plug IngotWeb.Plugs.RequireRole, role: :labeler, redirect_to: "/dashboard"
end

Role Hierarchy

The :admin role grants all permissions. Users with admin role will pass all role checks regardless of the required role.

Summary

Types

options()

@type options() :: keyword()