pow-auth / pow

Robust, modular, and extendable user authentication system
https://powauth.com
MIT License
1.58k stars 152 forks source link

How to migrate from `pow_mailer_layout` to `pow_mailer_layouts` #727

Closed nikcorg closed 3 months ago

nikcorg commented 3 months ago

Hello!

I spotted a warning mentioning that pow_mailer_layout had been deprecated and it is indeed even in the changelog.

Are there migration instructions anywhere to moving from the old to the new?

danschultzer commented 3 months ago

Yeah, I should have added more to that changelog. Updated both the changelog and the warning with #730, thanks!

This was part of moving towards Phoenix 1.7 syntax changes, so it follows the same rules. Instead of:

put_private(conn, :pow_mailer_layout, {MyAppWeb.LayoutView, :email})

You would do something like:

put_private(conn, :pow_mailer_layouts, html: {MyAppWeb.Layouts, :email}, text: false

# If you use layout for text
put_private(conn, :pow_mailer_layouts, html: {MyAppWeb.Layouts, :email}, text: {MyAppWeb.Layouts, :email_text}

The Layouts module may look something like:

defmodule MyAppWeb.Layouts do
  @moduledoc false
  use MyAppWeb, :html

  embed_templates "layouts/*.html"

  # If you use layout for text
  embed_templates "layouts/*.text", suffix: "_text"
end

You can see how text email uses a suffix to avoid conflicts with the embed_templates. This is so we can use the Phoenix HTML helpers. You could also split it in two separate modules (one for HTML emails and one for text emails).