liveview-native / live_view_native

A framework for building native applications with Phoenix LiveView
https://native.live/
MIT License
458 stars 19 forks source link

Remove "_lvn" parameter when redirect #143

Closed ByeongUkChoi closed 2 months ago

ByeongUkChoi commented 4 months ago

If redirect in IOS, remove "_lvn" parameter. If I want to hold "_lvn" parameter, How can I do?

Here is code and debug console. Suppose the token has expired and performed {:halt, push_redirect(socket, to: "/")} this line.

defmodule ElixirconfChatWeb.AssignUser do
  @moduledoc """
  Ensures common `assigns` are applied to all LiveViews attaching this hook.
  """
  import Phoenix.LiveView
  import Phoenix.Component, only: [assign: 2]

  alias ElixirconfChat.Auth

  def on_mount(_key, params, _session, socket) do
    connect_params = get_connect_params(socket)

    with token when is_binary(token) <- Map.get(params, "token", connect_params["token"]),
         {:ok, user_id} <- Auth.verify_token(token),
         %{} = user <- ElixirconfChat.Users.get_user(user_id) do
      socket =
        socket
        |> push_event("persist_token", %{token: token})
        |> assign(current_user: user, token: token)

      {:cont, socket}
    else
      _result ->
        {:halt, push_redirect(socket, to: "/")}    // <---- here!
    end
  end
end
[info] GET /chat/SFMyNTY.g2gDYQNuBgAuZjpVjgFiAAFRgA.7L5dP2z6CeQVlvC8y0OP0Gqn2dWZotlABch05p4tQMg/
[debug] Processing with ElixirconfChatWeb.ChatLive.Elixir.ElixirconfChatWeb.ChatLive/2
  Parameters: %{"_lvn" => %{"format" => "swiftui"}, "token" => "SFMyNTY.g2gDYQNuBgAuZjpVjgFiAAFRgA.7L5dP2z6CeQVlvC8y0OP0Gqn2dWZotlABch05p4tQMg"}
  Pipelines: [:browser]
[info] Sent 302 in 1ms
[info] GET /
[debug] Processing with ElixirconfChatWeb.AuthLive.Elixir.ElixirconfChatWeb.AuthLive/2
  Parameters: %{}
  Pipelines: [:browser]
bcardarella commented 3 months ago

@ByeongUkChoi the push_redirect should do a hard refresh of the app which should reconnect and send the interface object. However, are you saying that this isn't happening?

bcardarella commented 2 months ago

Closing again as I don't believe this is relevant for the upcoming v0.3 release. In addition, I recently resolved an issue where the _interface (formerly _lvn) is preserved: https://github.com/liveview-native/live_view_native/pull/181