dwyl / auth

🚪 🔐 UX-focussed Turnkey Authentication Solution for Web Apps/APIs (Documented, Tested & Maintained)
https://authdemo.fly.dev
GNU General Public License v2.0
135 stars 9 forks source link

Phoenix.Template.UndefinedError Could not render "live.html" for AuthWeb.LayoutView #233

Closed nelsonic closed 2 years ago

nelsonic commented 2 years ago

This is almost certainly PEBCAK ... but opening the issue to capture the solution in case someone else is trying to Add a LiveView to an existing (older) Phoenix App!

[error] #PID<0.693.0> running AuthWeb.Endpoint (connection #PID<0.692.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /groups
** (exit) an exception was raised:
    ** (Phoenix.Template.UndefinedError) Could not render "live.html" 
for AuthWeb.LayoutView, please define a matching clause for render/2 
or define a template at "lib/auth_web/templates/layout/*". The following templates were compiled:

* app.html
* nav.html
* root.html

Assigns:

%{__changed__: %{inner_content: true}, flash: %{}, 
inner_content: %Phoenix.LiveView.Rendered{dynamic: #Function<0.73895130/1 
in AuthWeb.GroupsLive.render/1>, 
root: true, static: ["<h1 class=\"\">Groups LiveView App Page!</h1>"]},  live_action: nil, 
socket: #Phoenix.LiveView.Socket<assigns: #Phoenix.LiveView.Socket.AssignsNotInSocket<>, 
endpoint: AuthWeb.Endpoint, id: "phx-Fx7p7d2lnTrKQwLj", 
parent_pid: nil, root_pid: nil, router: AuthWeb.Router, transport_pid: nil, 
view: AuthWeb.GroupsLive, ...>}

My instinct is: since the auth project hasn't used LiveView in the past, we need to add it manually to enable this ... 🤞

nelsonic commented 2 years ago

It was even easier than I thought! Renaming lib/auth_web/templates/layout/root.html.heex to lib/auth_web/templates/layout/live.html.heex fixed the issue. This makes sense because the configuration in auth/lib/auth_web.ex expects the layout file to be called live.html.heex:

https://github.com/dwyl/auth/blob/f6a72102fd72f99ba8c42d00083e22c2fdec917a/lib/auth_web.ex#L45-L52

Working as expected: http://localhost:4000/groups image

How epic is the groups feature? 😜 Closing. ✅