File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ import { spinner } from "../utilities/windows.js";
23
23
import { isLinuxServer } from "../utilities/linux.js" ;
24
24
import { VERSION } from "../version.js" ;
25
25
import { env } from "std-env" ;
26
+ import {
27
+ isPersonalAccessToken ,
28
+ NotPersonalAccessTokenError ,
29
+ } from "../utilities/isPersonalAccessToken.js" ;
26
30
27
31
export const LoginCommandOptions = CommonCommandOptions . extend ( {
28
32
apiUrl : z . string ( ) ,
@@ -84,6 +88,12 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
84
88
const accessTokenFromEnv = env . TRIGGER_ACCESS_TOKEN ;
85
89
86
90
if ( accessTokenFromEnv ) {
91
+ if ( ! isPersonalAccessToken ( accessTokenFromEnv ) ) {
92
+ throw new NotPersonalAccessTokenError (
93
+ "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"
94
+ ) ;
95
+ }
96
+
87
97
const auth = {
88
98
accessToken : accessTokenFromEnv ,
89
99
apiUrl : env . TRIGGER_API_URL ?? opts . defaultApiUrl ?? "https://api.trigger.dev" ,
@@ -292,6 +302,10 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
292
302
span . end ( ) ;
293
303
294
304
if ( options ?. embedded ) {
305
+ if ( e instanceof NotPersonalAccessTokenError ) {
306
+ throw e ;
307
+ }
308
+
295
309
return {
296
310
ok : false as const ,
297
311
error : e instanceof Error ? e . message : String ( e ) ,
Original file line number Diff line number Diff line change
1
+ const tokenPrefix = "tr_pat_" ;
2
+
3
+ export function isPersonalAccessToken ( token : string ) {
4
+ return token . startsWith ( tokenPrefix ) ;
5
+ }
6
+
7
+ export class NotPersonalAccessTokenError extends Error {
8
+ constructor ( message : string ) {
9
+ super ( message ) ;
10
+ this . name = "NotPersonalAccessTokenError" ;
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments