LiveReactNative.MobileSocket behaviour (live_react_native v0.0.3)

View Source

use this in your app's mobile socket and override resolve_user/2 and build_session/3. The library performs no authentication — you resolve identity with your existing verifier and gate routes with your existing live_session/on_mount hooks.

defmodule MyAppWeb.MobileSocket do
  use LiveReactNative.MobileSocket

  def resolve_user(%{"token" => t}, _info), do: MyApp.Auth.user_from_token(t)
  def build_session(user, _params, _info), do: %{"current_user" => user}
end

Resolve-if-present: a missing/invalid token yields current_user: nil (anonymous); the socket is not rejected. Per-route gating is your on_mount hooks' job.

Summary

Callbacks

build_session(user, params, connect_info)

@callback build_session(user :: term() | nil, params :: map(), connect_info :: map()) ::
  map()

resolve_user(params, connect_info)

@callback resolve_user(params :: map(), connect_info :: map()) ::
  {:ok, term() | nil} | {:error, term()}