Skip to content

Commit bb9bfc4

Browse files
authored
Normalize quickstart type comparison and improve port assignment logic (#1440)
* Normalize quickstart type comparison and improve port assignment logic * Fix quickstart setup command to return error on invalid port input
1 parent 694ee68 commit bb9bfc4

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

internal/cli/quickstarts.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,14 @@ func setupQuickstartCmd(cli *cli) *cobra.Command {
464464
RunE: func(cmd *cobra.Command, args []string) error {
465465
ctx := cmd.Context()
466466

467-
// Normalize the type to lowercase for comparison.
468-
normalizedType := strings.ToLower(inputs.Type)
469-
470467
if inputs.Type != "" {
468+
normalizedType := strings.ToLower(inputs.Type)
471469
if normalizedType != "vite" && normalizedType != "nextjs" {
472470
return fmt.Errorf("unsupported quickstart type: %s (supported types: vite, nextjs)", inputs.Type)
473471
}
474472
}
475473

476-
if err := qsType.Select(cmd, &inputs.Type, []string{"vite (React, Svelte, Vue, Vanilla JS)", "nextjs"}, nil); err != nil {
474+
if err := qsType.Select(cmd, &inputs.Type, []string{"vite", "nextjs"}, nil); err != nil {
477475
return err
478476
}
479477

@@ -489,31 +487,32 @@ func setupQuickstartCmd(cli *cli) *cobra.Command {
489487

490488
var appType, baseURL, envFileName string
491489
var callbacks, logoutURLs, origins, webOrigins []string
490+
var defaultPort string
492491

493-
switch {
494-
case strings.HasPrefix(normalizedType, "vite"):
492+
switch inputs.Type {
493+
case "vite":
495494
appType = appTypeSPA
496-
if inputs.Port == 0 {
497-
inputs.Port = 5173
498-
}
495+
defaultPort = "5173"
499496
envFileName = ".env"
500497

501-
case strings.HasPrefix(normalizedType, "nextjs"):
498+
case "nextjs":
502499
appType = appTypeRegularWeb
503-
if inputs.Port == 0 {
504-
inputs.Port = 3000
505-
}
500+
defaultPort = "3000"
506501
envFileName = ".env.local"
507502
}
508503

504+
if err := qsPort.Ask(cmd, &inputs.Port, &defaultPort); err != nil {
505+
return err
506+
}
507+
509508
if inputs.Port < 1024 || inputs.Port > 65535 {
510509
return fmt.Errorf("invalid port number: %d (must be between 1024 and 65535)", inputs.Port)
511510
}
512511

513512
baseURL = fmt.Sprintf("http://localhost:%d", inputs.Port)
514513

515514
// Configure URLs based on app type.
516-
if strings.HasPrefix(normalizedType, "vite") {
515+
if inputs.Type == "vite" {
517516
callbacks = []string{baseURL}
518517
logoutURLs = []string{baseURL}
519518
origins = []string{baseURL}
@@ -544,7 +543,7 @@ func setupQuickstartCmd(cli *cli) *cobra.Command {
544543
ClientMetadata: &metadata,
545544
}
546545

547-
if strings.HasPrefix(normalizedType, "vite") {
546+
if inputs.Type == "vite" {
548547
a.AllowedOrigins = &origins
549548
a.WebOrigins = &webOrigins
550549
}
@@ -564,12 +563,12 @@ func setupQuickstartCmd(cli *cli) *cobra.Command {
564563

565564
var envContent strings.Builder
566565

567-
switch {
568-
case strings.HasPrefix(normalizedType, "vite"):
566+
switch inputs.Type {
567+
case "vite":
569568
envContent.WriteString(fmt.Sprintf("VITE_AUTH0_DOMAIN=%s\n", tenant.Domain))
570569
envContent.WriteString(fmt.Sprintf("VITE_AUTH0_CLIENT_ID=%s\n", a.GetClientID()))
571570

572-
case strings.HasPrefix(normalizedType, "nextjs"):
571+
case "nextjs":
573572
secret, err := generateState(32)
574573
if err != nil {
575574
return fmt.Errorf("failed to generate AUTH0_SECRET: %w", err)

0 commit comments

Comments
 (0)