Skip to content
48 changes: 38 additions & 10 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@ EOF
}

binds := []string{}
for id, tmpl := range utils.Config.Auth.Email.Template {
if len(tmpl.ContentPath) == 0 {
continue
mountEmailTemplates := func(id, contentPath string) error {
if len(contentPath) == 0 {
return nil
}
hostPath := tmpl.ContentPath
if !filepath.IsAbs(tmpl.ContentPath) {
hostPath := contentPath
if !filepath.IsAbs(contentPath) {
var err error
hostPath, err = filepath.Abs(hostPath)
if err != nil {
Expand All @@ -481,6 +481,23 @@ EOF
}
dockerPath := path.Join(nginxEmailTemplateDir, id+filepath.Ext(hostPath))
binds = append(binds, fmt.Sprintf("%s:%s:rw", hostPath, dockerPath))
return nil
}

for id, tmpl := range utils.Config.Auth.Email.Template {
err := mountEmailTemplates(id, tmpl.ContentPath)
if err != nil {
return err
}
}

for id, tmpl := range utils.Config.Auth.Email.Notification {
if tmpl.Enabled {
err := mountEmailTemplates(id+"_notification", tmpl.ContentPath)
if err != nil {
return err
}
}
}

dockerPort := uint16(8000)
Expand Down Expand Up @@ -658,23 +675,34 @@ EOF
env = append(env, fmt.Sprintf("GOTRUE_SESSIONS_INACTIVITY_TIMEOUT=%v", utils.Config.Auth.Sessions.InactivityTimeout))
}

for id, tmpl := range utils.Config.Auth.Email.Template {
if len(tmpl.ContentPath) > 0 {
addMailerEnvVars := func(id, contentPath string, subject *string) {
if len(contentPath) > 0 {
env = append(env, fmt.Sprintf("GOTRUE_MAILER_TEMPLATES_%s=http://%s:%d/email/%s",
strings.ToUpper(id),
utils.KongId,
nginxTemplateServerPort,
id+filepath.Ext(tmpl.ContentPath),
id+filepath.Ext(contentPath),
))
}
if tmpl.Subject != nil {
if subject != nil {
env = append(env, fmt.Sprintf("GOTRUE_MAILER_SUBJECTS_%s=%s",
strings.ToUpper(id),
*tmpl.Subject,
*subject,
))
}
}

for id, tmpl := range utils.Config.Auth.Email.Template {
addMailerEnvVars(id, tmpl.ContentPath, tmpl.Subject)
}

for id, tmpl := range utils.Config.Auth.Email.Notification {
if tmpl.Enabled {
env = append(env, fmt.Sprintf("GOTRUE_MAILER_NOTIFICATIONS_%s_ENABLED=true", strings.ToUpper(id)))
addMailerEnvVars(id+"_notification", tmpl.ContentPath, tmpl.Subject)
}
}

switch {
case utils.Config.Auth.Sms.Twilio.Enabled:
env = append(
Expand Down
Loading