View Source LiveGuard.Config (Live Guard v0.1.8)
The config module of LiveGuard.
Summary
Types
The default configs.
Functions
The :current_user
config of LiveGuard.
The default configs of LiveGuard.
The :unauthorized_handler
config of LiveGuard.
Types
@type default_configs() :: [
current_user: :current_user,
unauthorized_handler: {LiveGuard.Helpers, :handle_unauthorized}
]
The default configs.
Functions
@spec current_user() :: atom()
The :current_user
config of LiveGuard.
You need to assign the current user to the socket before LiveGuard on_mount/4
callback is called..
The default assign name for the current user is :current_user
.
If you assign the current user as another than :current_user
you can set in the config:
config :live_guard, :current_user, :user
@spec default_configs() :: default_configs()
The default configs of LiveGuard.
The :unauthorized_handler
config of LiveGuard.
This function handles unauthorized LiveView lifecycle stages.
It's called when the allowed?/4
function returns false
.
By default it will put an error flash message with text "You don't have permission to do that!".
:mount
and :handle_params
LiveView lifecycle stages needs redirect after it detected as unauthorized.
In this case by default it will redirect to the home page (/
).
You can set a custom handler in the config:
config :live_guard, :unauthorized_handler, {MyModule, :my_handle_unauthorized}
It's called with 2 inputs, first is a socket
, second is is_redirect
(boolean).