Skip to content

Commit 0405819

Browse files
committed
Dont introspect token if already expired
1 parent 2a032b1 commit 0405819

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

packages/cli-kit/src/private/node/session/validate.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {applicationId} from './identity.js'
33
import {ApplicationToken, IdentityToken, validateCachedIdentityTokenStructure} from './schema.js'
44
import {validateIdentityToken} from './identity-token-validation.js'
55
import {sessionConstants} from '../constants.js'
6-
import {outputDebug} from '../../../public/node/output.js'
76
import {firstPartyDev} from '../../../public/node/context/local.js'
87
import {OAuthApplications} from '../session.js'
8+
import {outputDebug} from '@shopify/cli-kit/node/output'
99

1010
type ValidationResult = 'needs_refresh' | 'needs_full_auth' | 'ok'
1111

@@ -35,7 +35,6 @@ export async function validateSession(
3535
): Promise<ValidationResult> {
3636
if (!session) return 'needs_full_auth'
3737
const scopesAreValid = validateScopes(scopes, session.identity)
38-
const identityIsValid = await validateIdentityToken(session.identity.accessToken)
3938
if (!scopesAreValid) return 'needs_full_auth'
4039
let tokensAreExpired = isTokenExpired(session.identity)
4140

@@ -64,18 +63,18 @@ export async function validateSession(
6463
tokensAreExpired = tokensAreExpired || isTokenExpired(token)
6564
}
6665

67-
outputDebug(`
68-
The validation of the token for application/identity completed with the following results:
69-
- It's expired: ${tokensAreExpired}
70-
- It's invalid in identity: ${!identityIsValid}
71-
`)
66+
outputDebug(`- Token validation -> It's expired: ${tokensAreExpired}`)
7267

7368
if (!validateCachedIdentityTokenStructure(session.identity)) {
7469
return 'needs_full_auth'
7570
}
7671

7772
if (tokensAreExpired) return 'needs_refresh'
73+
74+
const identityIsValid = await validateIdentityToken(session.identity.accessToken)
75+
outputDebug(`- Token validation -> It's invalid in identity: ${!identityIsValid}`)
7876
if (!identityIsValid) return 'needs_full_auth'
77+
7978
return 'ok'
8079
}
8180

0 commit comments

Comments
 (0)