Skip to content
This repository has been archived by the owner on May 22, 2022. It is now read-only.

Commit

Permalink
fix: 404 template in case universal login is not set but custom domai…
Browse files Browse the repository at this point in the history
  • Loading branch information
alekc committed Sep 9, 2021
1 parent 534e1f8 commit fc0b42f
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions auth0/resource_auth0_branding.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,21 @@ func readBranding(d *schema.ResourceData, m interface{}) error {
return err
}

d.Set("favicon_url", b.FaviconURL)
d.Set("logo_url", b.LogoURL)
d.Set("colors", flattenBrandingColors(b.Colors))
d.Set("font", flattenBrandingFont(b.Font))
_ = d.Set("favicon_url", b.FaviconURL)
_ = d.Set("logo_url", b.LogoURL)
_ = d.Set("colors", flattenBrandingColors(b.Colors))
_ = d.Set("font", flattenBrandingFont(b.Font))

t, err := api.Tenant.Read()
if err != nil {
return err
}

if t.Flags.EnableCustomDomainInEmails != nil && *t.Flags.EnableCustomDomainInEmails {
ul, err := api.Branding.UniversalLogin()
if err != nil {
if err := assignUniversalLogin(d, m); err != nil {
d.SetId("")
return err
}

d.Set("universal_login", flattenBrandingUniversalLogin(ul))
}

return nil
Expand Down Expand Up @@ -195,6 +193,25 @@ func buildBrandingUniversalLogin(d *schema.ResourceData) *management.BrandingUni
return b
}

func assignUniversalLogin(d *schema.ResourceData, m interface{}) error {
api := m.(*management.Management)
ul, err := api.Branding.UniversalLogin()
if err != nil {
if mErr, ok := err.(management.Error); ok {
// if the custom domain is enabled, but custom universal login pages are not set
// management api will return a 404 template not found. If that's the case we can safely ignore the error.
// see https://github.com/alexkappa/terraform-provider-auth0/issues/380
if mErr.Status() == http.StatusNotFound {
return nil
}
}
return err
}

_ = d.Set("universal_login", flattenBrandingUniversalLogin(ul))
return nil
}

func flattenBrandingColors(brandingColors *management.BrandingColors) []interface{} {
m := make(map[string]interface{})
if brandingColors != nil {
Expand Down

0 comments on commit fc0b42f

Please sign in to comment.