File tree 5 files changed +74
-12
lines changed 5 files changed +74
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " trigger.dev " : patch
3
+ ---
4
+
5
+ Fix a bug where revoking the CLI token would prevent you from ever logging in again with the CLI.
Original file line number Diff line number Diff line change @@ -134,20 +134,27 @@ export async function authenticatePersonalAccessToken(
134
134
135
135
const hashedToken = hashToken ( token ) ;
136
136
137
- const personalAccessToken = await prisma . personalAccessToken . update ( {
137
+ const personalAccessToken = await prisma . personalAccessToken . findFirst ( {
138
138
where : {
139
139
hashedToken,
140
140
revokedAt : null ,
141
141
} ,
142
- data : {
143
- lastAccessedAt : new Date ( ) ,
144
- } ,
145
142
} ) ;
146
143
147
144
if ( ! personalAccessToken ) {
145
+ // The token may have been revoked or is entirely invalid
148
146
return ;
149
147
}
150
148
149
+ await prisma . personalAccessToken . update ( {
150
+ where : {
151
+ id : personalAccessToken . id ,
152
+ } ,
153
+ data : {
154
+ lastAccessedAt : new Date ( ) ,
155
+ } ,
156
+ } ) ;
157
+
151
158
const decryptedToken = decryptPersonalAccessToken ( personalAccessToken ) ;
152
159
153
160
if ( decryptedToken !== token ) {
@@ -210,6 +217,18 @@ export async function createPersonalAccessTokenFromAuthorizationCode(
210
217
} ,
211
218
} ) ;
212
219
220
+ if ( existingCliPersonalAccessToken . revokedAt ) {
221
+ // re-activate revoked CLI PAT so we can use it again
222
+ await prisma . personalAccessToken . update ( {
223
+ where : {
224
+ id : existingCliPersonalAccessToken . id ,
225
+ } ,
226
+ data : {
227
+ revokedAt : null ,
228
+ } ,
229
+ } ) ;
230
+ }
231
+
213
232
//we don't return the decrypted token
214
233
return {
215
234
id : existingCliPersonalAccessToken . id ,
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {
13
13
tracer ,
14
14
wrapCommandAction ,
15
15
} from "../cli/common.js" ;
16
- import { chalkLink } from "../utilities/cliOutput.js" ;
16
+ import { chalkLink , prettyError } from "../utilities/cliOutput.js" ;
17
17
import { readAuthConfigProfile , writeAuthConfigProfile } from "../utilities/configFiles.js" ;
18
18
import { getVersion } from "../utilities/getVersion.js" ;
19
19
import { printInitialBanner } from "../utilities/initialBanner.js" ;
@@ -109,10 +109,16 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
109
109
skipTelemetry : ! span . isRecording ( ) ,
110
110
logLevel : logger . loggerLevel ,
111
111
} ,
112
- opts . embedded
112
+ true
113
113
) ;
114
114
115
115
if ( ! whoAmIResult . success ) {
116
+ prettyError ( "Whoami failed" , whoAmIResult . error ) ;
117
+
118
+ if ( ! opts . embedded ) {
119
+ outro ( "Login failed" ) ;
120
+ }
121
+
116
122
throw new Error ( whoAmIResult . error ) ;
117
123
} else {
118
124
if ( ! opts . embedded ) {
Original file line number Diff line number Diff line change 1
- import { intro , note } from "@clack/prompts" ;
1
+ import { intro , note , outro } from "@clack/prompts" ;
2
2
import { chalkLink } from "../utilities/cliOutput.js" ;
3
3
import { logger } from "../utilities/logger.js" ;
4
4
import { isLoggedIn } from "../utilities/session.js" ;
@@ -66,11 +66,20 @@ export async function whoAmI(
66
66
if ( authentication . error === "fetch failed" ) {
67
67
loadingSpinner . stop ( "Fetch failed. Platform down?" ) ;
68
68
} else {
69
- loadingSpinner . stop (
70
- `You must login first. Use \`trigger.dev login --profile ${
71
- options ?. profile ?? "default"
72
- } \` to login.`
73
- ) ;
69
+ if ( embedded ) {
70
+ loadingSpinner . stop (
71
+ `Failed to check account details. You may want to run \`trigger.dev logout --profile ${
72
+ options ?. profile ?? "default"
73
+ } \` and try again.`
74
+ ) ;
75
+ } else {
76
+ loadingSpinner . stop (
77
+ `You must login first. Use \`trigger.dev login --profile ${
78
+ options ?. profile ?? "default"
79
+ } \` to login.`
80
+ ) ;
81
+ outro ( "Whoami failed" ) ;
82
+ }
74
83
}
75
84
76
85
return {
Original file line number Diff line number Diff line change @@ -65,6 +65,29 @@ export function prettyPrintDate(date: Date = new Date()) {
65
65
return formattedDate ;
66
66
}
67
67
68
+ export function prettyError ( header : string , body ?: string , footer ?: string ) {
69
+ const prefix = "Error: " ;
70
+ const indent = Array ( prefix . length ) . fill ( " " ) . join ( "" ) ;
71
+ const spacing = "\n\n" ;
72
+
73
+ const prettyPrefix = chalkError ( prefix ) ;
74
+
75
+ const withIndents = ( text ?: string ) =>
76
+ text
77
+ ?. split ( "\n" )
78
+ . map ( ( line ) => `${ indent } ${ line } ` )
79
+ . join ( "\n" ) ;
80
+
81
+ const prettyBody = withIndents ( body ) ;
82
+ const prettyFooter = withIndents ( footer ) ;
83
+
84
+ log . error (
85
+ `${ prettyPrefix } ${ header } ${ prettyBody ? `${ spacing } ${ prettyBody } ` : "" } ${
86
+ prettyFooter ? `${ spacing } ${ prettyFooter } ` : ""
87
+ } `
88
+ ) ;
89
+ }
90
+
68
91
export function prettyWarning ( header : string , body ?: string , footer ?: string ) {
69
92
const prefix = "Warning: " ;
70
93
const indent = Array ( prefix . length ) . fill ( " " ) . join ( "" ) ;
You can’t perform that action at this time.
0 commit comments