@@ -14,11 +14,12 @@ import {
14
14
wrapCommandAction ,
15
15
} from "../cli/common.js" ;
16
16
import { chalkLink } from "../utilities/colors.js" ;
17
- import { readAuthConfigFile , writeAuthConfigFile } from "../utilities/configFiles.js" ;
17
+ import { readAuthConfigProfile , writeAuthConfigProfile } from "../utilities/configFiles.js" ;
18
18
import { getVersion } from "../utilities/getVersion.js" ;
19
19
import { printInitialBanner } from "../utilities/initialBanner.js" ;
20
20
import { LoginResult } from "../utilities/session.js" ;
21
21
import { whoAmI } from "./whoami.js" ;
22
+ import { logger } from "../utilities/logger.js" ;
22
23
23
24
export const LoginCommandOptions = CommonCommandOptions . extend ( {
24
25
apiUrl : z . string ( ) ,
@@ -48,12 +49,13 @@ export async function loginCommand(options: unknown) {
48
49
}
49
50
50
51
async function _loginCommand ( options : LoginCommandOptions ) {
51
- return login ( { defaultApiUrl : options . apiUrl , embedded : false } ) ;
52
+ return login ( { defaultApiUrl : options . apiUrl , embedded : false , profile : options . profile } ) ;
52
53
}
53
54
54
55
export type LoginOptions = {
55
56
defaultApiUrl ?: string ;
56
57
embedded ?: boolean ;
58
+ profile ?: string ;
57
59
} ;
58
60
59
61
export async function login ( options ?: LoginOptions ) : Promise < LoginResult > {
@@ -63,16 +65,17 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
63
65
64
66
span . setAttributes ( {
65
67
"cli.config.apiUrl" : opts . defaultApiUrl ,
68
+ "cli.options.profile" : opts . profile ,
66
69
} ) ;
67
70
68
71
if ( ! opts . embedded ) {
69
72
intro ( "Logging in to Trigger.dev" ) ;
70
73
}
71
74
72
- const authConfig = readAuthConfigFile ( ) ;
75
+ const authConfig = readAuthConfigProfile ( options ?. profile ) ;
73
76
74
77
if ( authConfig && authConfig . accessToken ) {
75
- const whoAmIResult = await whoAmI ( undefined , opts . embedded ) ;
78
+ const whoAmIResult = await whoAmI ( { profile : options ?. profile ?? "default" , skipTelemetry : ! span . isRecording ( ) , logLevel : logger . loggerLevel } , opts . embedded ) ;
76
79
77
80
if ( ! whoAmIResult . success ) {
78
81
throw new Error ( whoAmIResult . error ) ;
@@ -106,6 +109,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
106
109
107
110
return {
108
111
ok : true as const ,
112
+ profile : options ?. profile ?? "default" ,
109
113
userId : whoAmIResult . data . userId ,
110
114
email : whoAmIResult . data . email ,
111
115
dashboardUrl : whoAmIResult . data . dashboardUrl ,
@@ -126,6 +130,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
126
130
127
131
return {
128
132
ok : true as const ,
133
+ profile : options ?. profile ?? "default" ,
129
134
userId : whoAmIResult . data . userId ,
130
135
email : whoAmIResult . data . email ,
131
136
dashboardUrl : whoAmIResult . data . dashboardUrl ,
@@ -170,9 +175,9 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
170
175
171
176
getPersonalAccessTokenSpinner . stop ( `Logged in with token ${ indexResult . obfuscatedToken } ` ) ;
172
177
173
- writeAuthConfigFile ( { accessToken : indexResult . token , apiUrl : opts . defaultApiUrl } ) ;
178
+ writeAuthConfigProfile ( { accessToken : indexResult . token , apiUrl : opts . defaultApiUrl } , options ?. profile ) ;
174
179
175
- const whoAmIResult = await whoAmI ( undefined , opts . embedded ) ;
180
+ const whoAmIResult = await whoAmI ( { profile : options ?. profile ?? "default" , skipTelemetry : ! span . isRecording ( ) , logLevel : logger . loggerLevel } , opts . embedded ) ;
176
181
177
182
if ( ! whoAmIResult . success ) {
178
183
throw new Error ( whoAmIResult . error ) ;
@@ -188,6 +193,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
188
193
189
194
return {
190
195
ok : true as const ,
196
+ profile : options ?. profile ?? "default" ,
191
197
userId : whoAmIResult . data . userId ,
192
198
email : whoAmIResult . data . email ,
193
199
dashboardUrl : whoAmIResult . data . dashboardUrl ,
0 commit comments