Skip to content

Commit

Permalink
feat: fetch partials on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jaime-amate committed Apr 18, 2024
1 parent 991429f commit 6a88327
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion internal/cli/universal_login_customize.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ var (
universalLoginPreviewAssets embed.FS
)

var allowedPromptsWithPartials = []management.PromptType{
management.PromptSignup,
management.PromptSignupID,
management.PromptSignupPassword,
management.PromptLogin,
management.PromptLoginID,
management.PromptLoginPassword,
}

type (
universalLoginBrandingData struct {
Applications []*applicationData `json:"applications"`
Expand Down Expand Up @@ -485,6 +494,12 @@ func fetchUniversalLoginBrandingData(
return err
})

var partials []*management.PromptPartials
group.Go(func() (err error) {
partials, err = fetchAllPartials(ctx, api)
return err
})

if err := group.Wait(); err != nil {
return nil, err
}
Expand All @@ -499,7 +514,8 @@ func fetchUniversalLoginBrandingData(
EnabledLocales: tenant.GetEnabledLocales(),
Domain: tenantDomain,
},
Prompts: []*promptData{prompt},
Prompts: []*promptData{prompt},
Partials: partials,
}, nil
}

Expand Down Expand Up @@ -656,6 +672,22 @@ func fetchPartial(ctx context.Context, api *auth0.API, prompt *partialData) (*ma
return partial, nil
}

func fetchAllPartials(ctx context.Context, api *auth0.API) ([]*management.PromptPartials, error) {
var partials []*management.PromptPartials

for _, prompt := range allowedPromptsWithPartials {
partial, err := api.Prompt.ReadPartials(ctx, prompt)

if err != nil {
return nil, err
}

partials = append(partials, partial)
}

return partials, nil
}

func saveUniversalLoginBrandingData(ctx context.Context, api *auth0.API, data *universalLoginBrandingData) error {
group, ctx := errgroup.WithContext(ctx)

Expand Down

0 comments on commit 6a88327

Please sign in to comment.