MCPcopy
hub / github.com/triggerdotdev/trigger.dev / login

Function login

packages/cli-v3/src/commands/login.ts:62–291  ·  view source on GitHub ↗
(options?: LoginOptions)

Source from the content-addressed store, hash-verified

60};
61
62export async function login(options?: LoginOptions): Promise<LoginResult> {
63 return await tracer.startActiveSpan("login", async (span) => {
64 try {
65 const opts = { defaultApiUrl: "https://api.trigger.dev", embedded: false, ...options };
66
67 span.setAttributes({
68 "cli.config.apiUrl": opts.defaultApiUrl,
69 "cli.options.profile": opts.profile,
70 });
71
72 if (!opts.embedded) {
73 intro("Logging in to Trigger.dev");
74 }
75
76 const accessTokenFromEnv = process.env.TRIGGER_ACCESS_TOKEN;
77
78 if (accessTokenFromEnv) {
79 const auth = {
80 accessToken: accessTokenFromEnv,
81 apiUrl: process.env.TRIGGER_API_URL ?? "https://api.trigger.dev",
82 };
83 const apiClient = new CliApiClient(auth.apiUrl, auth.accessToken);
84 const userData = await apiClient.whoAmI();
85
86 if (!userData.success) {
87 throw new Error(userData.error);
88 }
89
90 return {
91 ok: true as const,
92 profile: options?.profile ?? "default",
93 userId: userData.data.userId,
94 email: userData.data.email,
95 dashboardUrl: userData.data.dashboardUrl,
96 auth: {
97 accessToken: auth.accessToken,
98 apiUrl: auth.apiUrl,
99 },
100 };
101 }
102
103 const authConfig = readAuthConfigProfile(options?.profile);
104
105 if (authConfig && authConfig.accessToken) {
106 const whoAmIResult = await whoAmI(
107 {
108 profile: options?.profile ?? "default",
109 skipTelemetry: !span.isRecording(),
110 logLevel: logger.loggerLevel,
111 },
112 true
113 );
114
115 if (!whoAmIResult.success) {
116 prettyError("Unable to validate existing personal access token", whoAmIResult.error);
117
118 if (!opts.embedded) {
119 outro(

Callers 3

_deployCommandFunction · 0.90
_initCommandFunction · 0.90
_loginCommandFunction · 0.85

Calls 14

whoAmIMethod · 0.95
readAuthConfigProfileFunction · 0.85
whoAmIFunction · 0.85
prettyErrorFunction · 0.85
chalkLinkFunction · 0.85
spinnerFunction · 0.85
getPersonalAccessTokenFunction · 0.85
writeAuthConfigProfileFunction · 0.85
recordSpanExceptionFunction · 0.85
startActiveSpanMethod · 0.80
createAuthorizationCodeFunction · 0.70
errorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…