View Source LiveGuard (Live Guard v0.1.8)

A simple module with on_mount/4 callback. This can used in Phoenix LiveView applications. The main goal is to protect the Phoenix LiveView lifecycle stages easily. It uses the attach_hook/4 function to authorize attachable LiveView lifecycle stages (:handle_params, :handle_event, :handle_info and :handle_async).

Summary

Types

The attachable LiveView lifecycle stages (:handle_params, :handle_event, :handle_info and :handle_async).

Functions

All attachable LiveView lifecycle stages by LiveGuard.

Optional

This macro can be used with @before_compile hook.

Optional

This macro can be used with @before_compile hook.

You can find the documentation of on_mount/1 here.

Types

Link to this type

attachable_lifecycle_stages()

View Source
@type attachable_lifecycle_stages() ::
  :handle_params | :handle_event | :handle_info | :handle_async

The attachable LiveView lifecycle stages (:handle_params, :handle_event, :handle_info and :handle_async).

Functions

Link to this function

attachable_lifecycle_stages()

View Source
@spec attachable_lifecycle_stages() :: [attachable_lifecycle_stages()]

All attachable LiveView lifecycle stages by LiveGuard.

Link to this macro

before_compile_allowed(env)

View Source (macro)
@spec before_compile_allowed(env :: map()) :: tuple()

Optional

This macro can be used with @before_compile hook.

It will add a catch-all allowed?/4 function returning true, to the end the module.

Example

defimpl LiveGuard.Allowed, for: User do
  @before_compile {LiveGuard, :before_compile_allowed}

  # some code...
end
Link to this macro

before_compile_guarded_stages(env)

View Source (macro)
@spec before_compile_guarded_stages(env :: map()) :: tuple()

Optional

This macro can be used with @before_compile hook.

It will add a catch-all guarded_stages/1 function returning the valid attachable LiveView lifecycle stages (:handle_params, :handle_event, :handle_info and :handle_async), to the end the module.

Example

defimpl LiveGuard.GuardedStages, for: Atom do
  @before_compile {LiveGuard, :before_compile_guarded_stages}

  # some code...
end
Link to this function

on_mount(on_mount_name, params, session, socket)

View Source
@spec on_mount(
  on_mount_name :: :default,
  params :: Phoenix.LiveView.unsigned_params() | :not_mounted_at_router,
  session :: map(),
  socket :: Phoenix.LiveView.Socket.t()
) :: {:cont | :halt, socket :: Phoenix.LiveView.Socket.t()}

You can find the documentation of on_mount/1 here.