We've moved discussions to Discord

How do I change forgot password reset url in a multitenant app with multiple domains?

Peter Marcano
Basically have lots of domains going to be using the app and the devise forgot password devise link wants to use the domain provided in the Jumpstart Config... any way to change this?
Chris Oliver
You should be able to update the devise mailer view to include the domain in it.
Carter Sowers
Hey , this thread is 2 years old, but any chance you can share how you resolved this issue? Thank you.
Carter Sowers
What I ended up doing was overriding Devise::Mailer and setting the account instance variable for each Devise mailer there.

class DeviseMailer < Devise::Mailer
  layout "customer_mailer"

  def confirmation_instructions(record, token, opts={})
    @account = Current.account
    if @account.domain.present?
      @confirmation_link = "https://#{@account.domain}/users/confirmation?confirmation_token=#{token}"
    else
      if Rails.env.development?
        @confirmation_link = "http://#{@account.subdomain}.lvh.me:3000/users/confirmation?confirmation_token=#{token}"
      else
        @confirmation_link = "https://#{@account.subdomain}.example.com/users/confirmation?confirmation_token=#{token}"
      end      
    end

    opts[:from] = "you.can.override.from@here.com"
    opts[:reply_to] = "you.can.override.reply_to@here.com"
    opts[:subject] = "You can override subject here."
    super
  end

end

And then in the mailer views themselves, simply use the instance vars.

confirmation_instructions.html.erb
<h1><%= @account.name %></h1>
<p><%= t('.greeting', recipient: @email) %></p>

<p><%= t('.instruction') %></p>

<p><a href="<%= @confirmation_link %>">Confirm my account</a></p>

A note about the registrations controller: You may experience a race condition if you try to send a mailer before the account_user record is saved to the database.

For that you might need to call:

resource.skip_confirmation_notification!

And then after the account_user record is saved you would need to manually trigger the confirmation email to send:

current_user.send_confirmation_instructions
Notifications
You’re not receiving notifications from this thread.