Validating LiveView parameters

router.ex

live "/tokens/:id", TokenLive, :index

on that :id I’d like to apply the function

EIP55.valid?(id_here)

and return 404 (or redirect) if the function returns false

I’m checking out some libraries such a GitHub - smanolloff/phoenix_params: A plug for Phoenix apps that validates and transforms HTTP request params. but that seems overkill, are those really needed? How to apply them to liveview?

thanks

since you want a custom validation, you could just define and use your own plug in the pipeline or do a similar operation in the LV if it’s only going to work for one liveview.

defmodule MyAppWeb.Plugs.EIP55Validator do
  import Plug.Conn

  def init(default), do: default

  def call(%Plug.Conn{params: %{"id" => id}} = conn, _default) do
    case EIP55.valid?(id) do
      true -> conn
      false -> raise MyAppWeb.NotFoundError
    end
  end
end

thanks, I got it working :+1: