View Source LiveGuard.Helpers (Live Guard v0.1.8)

Helpers module of LiveGuard.

Summary

Functions

This function handles unauthorized LiveView lifecycle stages. It's called when the allowed?/4 function returns false.

Functions

Link to this function

handle_unauthorized(socket, is_redirect)

View Source
@spec handle_unauthorized(
  socket :: Phoenix.LiveView.Socket.t(),
  is_redirect :: boolean()
) ::
  Phoenix.LiveView.Socket.t()

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).