Skip to content

Commit 02dbeea

Browse files
committed
Don't require login to use turso db shell
Fixes #879 Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
1 parent e1d76ca commit 02dbeea

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

internal/cmd/db_shell.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var shellCmd = &cobra.Command{
9797
// Makes sure localhost URL or self-hosted will work even if not authenticated
9898
// to turso. The token code will check for auth
9999
if !isURL(nameOrUrl) {
100+
VerifyUserIsLoggedIn()
100101
client, err := authedTursoClient()
101102
if err != nil {
102103
return fmt.Errorf("could not create turso client: %w", err)

internal/cmd/root.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func requiresLogin(cmd *cobra.Command) bool {
3838
"turso config set token",
3939
"turso update",
4040
"turso completion",
41+
"turso db shell",
4142
}
4243
for _, allowed := range allowlist {
4344
if strings.HasPrefix(path, allowed) {
@@ -104,13 +105,17 @@ func init() {
104105
if !requiresLogin(cmd) {
105106
return
106107
}
107-
_, err := getAccessToken()
108-
if errors.Is(err, ErrNotLoggedIn) {
109-
fmt.Printf("You are not logged in, please login with %s before running other commands.\n", internal.Emph("turso auth login"))
110-
os.Exit(0)
111-
}
108+
VerifyUserIsLoggedIn()
112109
}
113110
rootCmd.CompletionOptions.HiddenDefaultCmd = true
114111
flags.AddDebugFlag(rootCmd)
115112
flags.AddResetConfigFlag(rootCmd)
116113
}
114+
115+
func VerifyUserIsLoggedIn() {
116+
_, err := getAccessToken()
117+
if errors.Is(err, ErrNotLoggedIn) {
118+
fmt.Printf("You are not logged in, please login with %s before running other commands.\n", internal.Emph("turso auth login"))
119+
os.Exit(0)
120+
}
121+
}

0 commit comments

Comments
 (0)