cassette_plug v1.1.6 Cassette.Plug.RequireRolePlug View Source
Plug to check presence of user roles
Link to this section Summary
Functions
Callback implementation for Plug.call/2
Fetches the current user from the session
Callback implementation for Plug.init/1
Tests if the user has (raw) roles
Tests if the user has roles
Link to this section Types
Link to this type
role_param()
View Source
role_param() :: String.t() | [String.t()] | (Plug.Conn.t() -> String.t())
Link to this section Functions
Callback implementation for Plug.call/2
.
Link to this function
current_user(conn)
View Source
current_user(Plug.Conn.t()) :: Cassette.User.t() | nil
Fetches the current user from the session.
Returns nil
if has no user
Callback implementation for Plug.init/1
.
Link to this function
raw_role?(conn, roles)
View Source
raw_role?(Plug.Conn.t(), role_param()) :: boolean()
Tests if the user has (raw) roles.
Arguments follow the same logic as role?/2 but they are forwarded to Cassette.User.has_raw_role?/2
Link to this function
role?(conn, roles, opts)
View Source
role?(Plug.Conn.t(), role_param(), Keyword.t()) :: boolean()
Tests if the user has roles.
When roles is a list, tests if current_user
has any of the roles.
When roles ia function, it will receive the Plug.Conn.t
and must return role to validate.
Returns false
if there is no user in the session.