Skip to content

Commit 1f29a50

Browse files
author
Lasim
committed
feat(gateway): update teams and whoami commands to use backend URL
1 parent bf6fba0 commit 1f29a50

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

services/gateway/src/commands/teams.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export function registerTeamsCommand(program: Command) {
99
program
1010
.command('teams')
1111
.description('List your teams and team information')
12-
.option('--url <url>', 'DeployStack backend URL (for development)', 'https://cloud.deploystack.io')
12+
.option('--url <url>', 'DeployStack backend URL (override stored URL)')
1313
.action(async (options) => {
1414
const storage = new CredentialStorage();
15+
let backendUrl = 'https://cloud.deploystack.io'; // Default fallback
1516

1617
try {
1718
// Check authentication
@@ -28,7 +29,9 @@ export function registerTeamsCommand(program: Command) {
2829
process.exit(1);
2930
}
3031

31-
const api = new DeployStackAPI(credentials, options.url);
32+
// Use stored baseUrl or command line override
33+
backendUrl = options.url || credentials.baseUrl || 'https://cloud.deploystack.io';
34+
const api = new DeployStackAPI(credentials, backendUrl);
3235

3336
// Get teams
3437
const teams = await api.getUserTeams();
@@ -83,8 +86,8 @@ export function registerTeamsCommand(program: Command) {
8386
console.log(chalk.gray(`💡 Run 'deploystack login' to refresh your authentication`));
8487
} else if (error.code === 'NETWORK_ERROR') {
8588
console.log(chalk.gray('💡 Check your internet connection and try again'));
86-
if (options.url !== 'https://cloud.deploystack.io') {
87-
console.log(chalk.gray(`💡 Make sure your development server is running at ${options.url}`));
89+
if (backendUrl !== 'https://cloud.deploystack.io') {
90+
console.log(chalk.gray(`💡 Make sure your development server is running at ${backendUrl}`));
8891
}
8992
} else if (error.code === 'INVALID_TOKEN') {
9093
console.log(chalk.gray('💡 Your token may not have permission to view teams'));

services/gateway/src/commands/whoami.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export function registerWhoamiCommand(program: Command) {
1010
program
1111
.command('whoami')
1212
.description('Display current user information')
13-
.option('--url <url>', 'DeployStack backend URL (for development)', 'https://cloud.deploystack.io')
13+
.option('--url <url>', 'DeployStack backend URL (override stored URL)')
1414
.action(async (options) => {
1515
const storage = new CredentialStorage();
16+
let backendUrl = 'https://cloud.deploystack.io'; // Default fallback
1617

1718
try {
1819
// Check authentication
@@ -29,7 +30,10 @@ export function registerWhoamiCommand(program: Command) {
2930
process.exit(1);
3031
}
3132

32-
const api = new DeployStackAPI(credentials, options.url);
33+
// Use stored baseUrl or command line override
34+
backendUrl = options.url || credentials.baseUrl || 'https://cloud.deploystack.io';
35+
36+
const api = new DeployStackAPI(credentials, backendUrl);
3337

3438
// Get user info
3539
const userInfo = await api.getUserInfo();
@@ -38,7 +42,8 @@ export function registerWhoamiCommand(program: Command) {
3842

3943
// Display user information
4044
const userEmail = userInfo.email || api.getUserEmail();
41-
console.log(chalk.blue(`👋 You are logged in with an OAuth Token, associated with ${userEmail}\n`));
45+
console.log(chalk.blue(`👋 You are logged in with an OAuth Token, associated with ${userEmail}`));
46+
console.log(chalk.gray(`🌐 Using backend: ${backendUrl}\n`));
4247

4348
// Display account info in table format if accounts exist
4449
if (accounts.length > 0) {
@@ -108,8 +113,8 @@ export function registerWhoamiCommand(program: Command) {
108113
console.log(chalk.gray(`💡 Run 'deploystack login' to refresh your authentication`));
109114
} else if (error.code === 'NETWORK_ERROR') {
110115
console.log(chalk.gray('💡 Check your internet connection and try again'));
111-
if (options.url !== 'https://cloud.deploystack.io') {
112-
console.log(chalk.gray(`💡 Make sure your development server is running at ${options.url}`));
116+
if (backendUrl !== 'https://cloud.deploystack.io') {
117+
console.log(chalk.gray(`💡 Make sure your development server is running at ${backendUrl}`));
113118
}
114119
}
115120
} else {

services/gateway/src/core/auth/oauth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class OAuth2Client {
110110
refreshToken: tokenResponse.refresh_token,
111111
expiresAt: Date.now() + (tokenResponse.expires_in * 1000),
112112
userEmail: userInfo.email,
113+
baseUrl: this.config.baseUrl, // Store the backend URL used during login
113114
accounts: [] // Will be populated from user info if available
114115
};
115116

services/gateway/src/core/auth/storage.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ export class CredentialStorage {
5858
* @returns Stored credentials or null if not found
5959
*/
6060
async getCredentials(): Promise<StoredCredentials | null> {
61-
console.log('🔍 Attempting to retrieve stored credentials...');
61+
// REMOVED: console.log('🔍 Attempting to retrieve stored credentials...');
6262

6363
// First try encrypted file (more reliable for single-user scenario)
6464
try {
65-
console.log('📁 Checking encrypted file:', this.fallbackFile);
65+
// REMOVED: console.log('📁 Checking encrypted file:', this.fallbackFile);
6666
const encryptedCredentials = await this.retrieveEncrypted();
6767
if (encryptedCredentials) {
68-
console.log('✓ Found credentials in encrypted file');
68+
// REMOVED: console.log('✓ Found credentials in encrypted file');
6969
return encryptedCredentials;
7070
} else {
71-
console.log('⚠ No credentials found in encrypted file');
71+
// REMOVED: console.log('⚠ No credentials found in encrypted file');
7272
}
7373
} catch (error) {
74-
console.log('❌ Error reading encrypted file:', (error as Error)?.message);
74+
// REMOVED: console.log('❌ Error reading encrypted file:', (error as Error)?.message);
7575
}
7676

7777
// Fallback to keychain
7878
try {
79-
console.log('🔑 Checking OS keychain...');
79+
// REMOVED: console.log('🔑 Checking OS keychain...');
8080
const accounts = await this.getStoredAccounts();
81-
console.log('📋 Found accounts:', accounts);
81+
// REMOVED: console.log('📋 Found accounts:', accounts);
8282

8383
if (accounts.length > 0) {
8484
// Try each account until we find valid credentials
@@ -87,22 +87,22 @@ export class CredentialStorage {
8787
const stored = await keyring.getPassword(this.serviceName, account);
8888
if (stored) {
8989
const credentials = JSON.parse(stored);
90-
console.log('✓ Found credentials in OS keychain for:', account);
90+
// REMOVED: console.log('✓ Found credentials in OS keychain for:', account);
9191
return credentials;
9292
}
9393
} catch (error) {
94-
console.log('⚠ Failed to retrieve credentials for account:', account);
94+
// REMOVED: console.log('⚠ Failed to retrieve credentials for account:', account);
9595
continue;
9696
}
9797
}
9898
} else {
99-
console.log('⚠ No accounts found in keychain');
99+
// REMOVED: console.log('⚠ No accounts found in keychain');
100100
}
101101
} catch (error) {
102-
console.log('❌ Error accessing keychain:', (error as Error)?.message);
102+
// REMOVED: console.log('❌ Error accessing keychain:', (error as Error)?.message);
103103
}
104104

105-
console.log('❌ No credentials found in any storage method');
105+
// REMOVED: console.log('❌ No credentials found in any storage method');
106106
return null;
107107
}
108108

services/gateway/src/types/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface StoredCredentials {
33
refreshToken: string;
44
expiresAt: number;
55
userEmail: string;
6+
baseUrl: string; // Store the backend URL used during login
67
accounts: Array<{
78
id: string;
89
name: string;

services/gateway/src/utils/auth-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface AuthConfig {
22
clientId: string;
3+
baseUrl: string; // Store the base URL
34
authUrl: string;
45
tokenUrl: string;
56
userInfoUrl: string;
@@ -14,6 +15,7 @@ export interface AuthConfig {
1415
*/
1516
export const DEFAULT_AUTH_CONFIG: AuthConfig = {
1617
clientId: 'deploystack-gateway-cli',
18+
baseUrl: 'https://cloud.deploystack.io',
1719
authUrl: 'https://cloud.deploystack.io/api/oauth2/auth',
1820
tokenUrl: 'https://cloud.deploystack.io/api/oauth2/token',
1921
userInfoUrl: 'https://cloud.deploystack.io/api/oauth2/userinfo',
@@ -37,6 +39,7 @@ export const DEFAULT_AUTH_CONFIG: AuthConfig = {
3739
export function buildAuthConfig(baseUrl: string): AuthConfig {
3840
return {
3941
...DEFAULT_AUTH_CONFIG,
42+
baseUrl: baseUrl, // Store the base URL
4043
authUrl: `${baseUrl}/api/oauth2/auth`,
4144
tokenUrl: `${baseUrl}/api/oauth2/token`,
4245
userInfoUrl: `${baseUrl}/api/oauth2/userinfo`,

0 commit comments

Comments
 (0)