diff --git a/cmd/login.go b/cmd/login.go index d1d4086fd..64de8c77a 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -42,7 +42,7 @@ var ( PostRunE: func(cmd *cobra.Command, args []string) error { if prof := viper.GetString("PROFILE"); viper.IsSet("PROFILE") { // Failure to save should block subsequent commands on CI - return utils.WriteFile(utils.ProfilePath, []byte(prof), afero.NewOsFs()) + return utils.SaveProfileName(prof, afero.NewOsFs()) } return nil }, diff --git a/internal/utils/misc.go b/internal/utils/misc.go index b47a8a3eb..f04d5f917 100644 --- a/internal/utils/misc.go +++ b/internal/utils/misc.go @@ -75,7 +75,6 @@ var ( PoolerVersionPath = filepath.Join(TempDir, "pooler-version") RealtimeVersionPath = filepath.Join(TempDir, "realtime-version") CliVersionPath = filepath.Join(TempDir, "cli-latest") - ProfilePath = filepath.Join(TempDir, "profile") CurrBranchPath = filepath.Join(SupabaseDirPath, ".branches", "_current_branch") SchemasDir = filepath.Join(SupabaseDirPath, "schemas") MigrationsDir = filepath.Join(SupabaseDirPath, "migrations") diff --git a/internal/utils/profile.go b/internal/utils/profile.go index 723b52fa8..e9495a481 100644 --- a/internal/utils/profile.go +++ b/internal/utils/profile.go @@ -3,6 +3,8 @@ package utils import ( "context" "fmt" + "os" + "path/filepath" "sort" "strings" @@ -121,8 +123,11 @@ func getProfileName(fsys afero.Fs) string { if prof := viper.GetString("PROFILE"); viper.IsSet("PROFILE") { fmt.Fprintln(debuglogger, "Loading profile from flag:", prof) return prof - } else if content, err := afero.ReadFile(fsys, ProfilePath); err == nil { - fmt.Fprintln(debuglogger, "Loading profile from file:", ProfilePath) + } else if profilePath, err := getProfilePath(); err != nil { + fmt.Fprintln(debuglogger, err) + return prof + } else if content, err := afero.ReadFile(fsys, profilePath); err == nil { + fmt.Fprintln(debuglogger, "Loading profile from file:", profilePath) return string(content) } else { fmt.Fprintln(debuglogger, err) @@ -130,6 +135,22 @@ func getProfileName(fsys afero.Fs) string { } } +func getProfilePath() (string, error) { + home, err := os.UserHomeDir() + if err != nil { + return "", errors.Errorf("failed to get $HOME directory: %w", err) + } + return filepath.Join(home, ".supabase", "profile"), nil +} + +func SaveProfileName(prof string, fsys afero.Fs) error { + profilePath, err := getProfilePath() + if err != nil { + return err + } + return WriteFile(profilePath, []byte(prof), fsys) +} + func AwsRegions() []string { result := make([]string, len(allProfiles[0].ProjectRegions)) for i, region := range allProfiles[0].ProjectRegions {