@@ -30,7 +30,10 @@ import { env, isCI } from "std-env";
3030import { CLOUD_API_URL } from "../consts.js" ;
3131import {
3232 isPersonalAccessToken ,
33+ isOrganizationAccessToken ,
34+ validateAccessToken ,
3335 NotPersonalAccessTokenError ,
36+ NotAccessTokenError ,
3437} from "../utilities/isPersonalAccessToken.js" ;
3538import { links } from "@trigger.dev/core/v3" ;
3639
@@ -94,8 +97,12 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
9497 const accessTokenFromEnv = env . TRIGGER_ACCESS_TOKEN ;
9598
9699 if ( accessTokenFromEnv ) {
97- if ( ! isPersonalAccessToken ( accessTokenFromEnv ) ) {
98- throw new NotPersonalAccessTokenError (
100+ const validationResult = validateAccessToken ( accessTokenFromEnv ) ;
101+
102+ if ( ! validationResult . success ) {
103+ // We deliberately don't surface the existence of organization access tokens to the user for now, as they're only used internally.
104+ // Once we expose them in the application, we should also communicate that option here.
105+ throw new NotAccessTokenError (
99106 "Your TRIGGER_ACCESS_TOKEN is not a Personal Access Token, they start with 'tr_pat_'. You can generate one here: https://cloud.trigger.dev/account/tokens"
100107 ) ;
101108 }
@@ -119,6 +126,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
119126 dashboardUrl : userData . data . dashboardUrl ,
120127 auth : {
121128 accessToken : auth . accessToken ,
129+ tokenType : validationResult . type ,
122130 apiUrl : auth . apiUrl ,
123131 } ,
124132 } ;
@@ -188,6 +196,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
188196 auth : {
189197 accessToken : authConfig . accessToken ,
190198 apiUrl : authConfig . apiUrl ?? opts . defaultApiUrl ,
199+ tokenType : "personal" as const ,
191200 } ,
192201 } ;
193202 }
@@ -209,6 +218,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
209218 auth : {
210219 accessToken : authConfig . accessToken ,
211220 apiUrl : authConfig . apiUrl ?? opts . defaultApiUrl ,
221+ tokenType : "personal" as const ,
212222 } ,
213223 } ;
214224 }
@@ -270,7 +280,10 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
270280 getPersonalAccessTokenSpinner . stop ( `Logged in with token ${ indexResult . obfuscatedToken } ` ) ;
271281
272282 writeAuthConfigProfile (
273- { accessToken : indexResult . token , apiUrl : opts . defaultApiUrl } ,
283+ {
284+ accessToken : indexResult . token ,
285+ apiUrl : opts . defaultApiUrl ,
286+ } ,
274287 options ?. profile
275288 ) ;
276289
@@ -309,6 +322,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
309322 auth : {
310323 accessToken : indexResult . token ,
311324 apiUrl : authConfig ?. apiUrl ?? opts . defaultApiUrl ,
325+ tokenType : "personal" as const ,
312326 } ,
313327 } ;
314328 } catch ( e ) {
0 commit comments