Skip to content

Commit f17b89f

Browse files
committed
update client.go
1 parent 01dc4cd commit f17b89f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pkg/auth/client.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ import (
1212

1313
// GetAuthenticatedClient returns a Kernel client with appropriate authentication
1414
func GetAuthenticatedClient(opts ...option.RequestOption) (*kernel.Client, error) {
15-
// Try to use stored OAuth tokens first
15+
// Try to use API key first if available
16+
apiKey := os.Getenv("KERNEL_API_KEY")
17+
if apiKey != "" {
18+
pterm.Debug.Println("Using API key authentication")
19+
20+
authOpts := append(opts, option.WithHeader("Authorization", "Bearer "+apiKey))
21+
client := kernel.NewClient(authOpts...)
22+
return &client, nil
23+
}
24+
25+
// Fallback to OAuth tokens if no API key is available
1626
tokens, err := LoadTokens()
1727
if err == nil {
1828
// Check if access token is expired and refresh if needed
@@ -41,15 +51,6 @@ func GetAuthenticatedClient(opts ...option.RequestOption) (*kernel.Client, error
4151
return &client, nil
4252
}
4353

44-
// Fallback to API key if no OAuth tokens are available
45-
apiKey := os.Getenv("KERNEL_API_KEY")
46-
if apiKey == "" {
47-
return nil, fmt.Errorf("no authentication available. Please run 'kernel login' or set KERNEL_API_KEY environment variable")
48-
}
49-
50-
pterm.Debug.Println("Using API key authentication (fallback)")
51-
52-
authOpts := append(opts, option.WithHeader("Authorization", "Bearer "+apiKey))
53-
client := kernel.NewClient(authOpts...)
54-
return &client, nil
54+
// No authentication available
55+
return nil, fmt.Errorf("no authentication available. Please run 'kernel login' or set KERNEL_API_KEY environment variable")
5556
}

0 commit comments

Comments
 (0)