Skip to content

Commit e14d7e7

Browse files
fix(auth): skip validateExp when allowExpired=true
1 parent 1371057 commit e14d7e7

File tree

1 file changed

+81
-81
lines changed

1 file changed

+81
-81
lines changed

packages/core/auth-js/src/GoTrueClient.ts

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,9 @@ export default class GoTrueClient {
742742
*/
743743
async signInWithWeb3(credentials: Web3Credentials): Promise<
744744
| {
745-
data: { session: Session; user: User }
746-
error: null
747-
}
745+
data: { session: Session; user: User }
746+
error: null
747+
}
748748
| { data: { session: null; user: null }; error: AuthError }
749749
> {
750750
const { chain } = credentials
@@ -1021,9 +1021,9 @@ export default class GoTrueClient {
10211021
: []),
10221022
...(options?.signInWithSolana?.resources?.length
10231023
? [
1024-
'Resources',
1025-
...options.signInWithSolana.resources.map((resource) => `- ${resource}`),
1026-
]
1024+
'Resources',
1025+
...options.signInWithSolana.resources.map((resource) => `- ${resource}`),
1026+
]
10271027
: []),
10281028
].join('\n')
10291029

@@ -1084,9 +1084,9 @@ export default class GoTrueClient {
10841084

10851085
private async _exchangeCodeForSession(authCode: string): Promise<
10861086
| {
1087-
data: { session: Session; user: User; redirectType: string | null }
1088-
error: null
1089-
}
1087+
data: { session: Session; user: User; redirectType: string | null }
1088+
error: null
1089+
}
10901090
| { data: { session: null; user: null; redirectType: null }; error: AuthError }
10911091
> {
10921092
const storageItem = await getItemAsync(this.storage, `${this.storageKey}-code-verifier`)
@@ -1533,23 +1533,23 @@ export default class GoTrueClient {
15331533
fn: (
15341534
result:
15351535
| {
1536-
data: {
1537-
session: Session
1538-
}
1539-
error: null
1536+
data: {
1537+
session: Session
15401538
}
1539+
error: null
1540+
}
15411541
| {
1542-
data: {
1543-
session: null
1544-
}
1545-
error: AuthError
1542+
data: {
1543+
session: null
15461544
}
1545+
error: AuthError
1546+
}
15471547
| {
1548-
data: {
1549-
session: null
1550-
}
1551-
error: null
1548+
data: {
1549+
session: null
15521550
}
1551+
error: null
1552+
}
15531553
) => Promise<R>
15541554
): Promise<R> {
15551555
this._debug('#_useSession', 'begin')
@@ -1571,23 +1571,23 @@ export default class GoTrueClient {
15711571
*/
15721572
private async __loadSession(): Promise<
15731573
| {
1574-
data: {
1575-
session: Session
1576-
}
1577-
error: null
1574+
data: {
1575+
session: Session
15781576
}
1577+
error: null
1578+
}
15791579
| {
1580-
data: {
1581-
session: null
1582-
}
1583-
error: AuthError
1580+
data: {
1581+
session: null
15841582
}
1583+
error: AuthError
1584+
}
15851585
| {
1586-
data: {
1587-
session: null
1588-
}
1589-
error: null
1586+
data: {
1587+
session: null
15901588
}
1589+
error: null
1590+
}
15911591
> {
15921592
this._debug('#__loadSession()', 'begin')
15931593

@@ -1943,9 +1943,9 @@ export default class GoTrueClient {
19431943
callbackUrlType: string
19441944
): Promise<
19451945
| {
1946-
data: { session: Session; redirectType: string | null }
1947-
error: null
1948-
}
1946+
data: { session: Session; redirectType: string | null }
1947+
error: null
1948+
}
19491949
| { data: { session: null; redirectType: null }; error: AuthError }
19501950
> {
19511951
try {
@@ -2181,13 +2181,13 @@ export default class GoTrueClient {
21812181
this._debug('#onAuthStateChange()', 'registered callback with id', id)
21822182

21832183
this.stateChangeEmitters.set(id, subscription)
2184-
;(async () => {
2185-
await this.initializePromise
2184+
; (async () => {
2185+
await this.initializePromise
21862186

2187-
await this._acquireLock(-1, async () => {
2188-
this._emitInitialSession(id)
2189-
})
2190-
})()
2187+
await this._acquireLock(-1, async () => {
2188+
this._emitInitialSession(id)
2189+
})
2190+
})()
21912191

21922192
return { data: { subscription } }
21932193
}
@@ -2226,9 +2226,9 @@ export default class GoTrueClient {
22262226
} = {}
22272227
): Promise<
22282228
| {
2229-
data: {}
2230-
error: null
2231-
}
2229+
data: {}
2230+
error: null
2231+
}
22322232
| { data: null; error: AuthError }
22332233
> {
22342234
let codeChallenge: string | null = null
@@ -2266,11 +2266,11 @@ export default class GoTrueClient {
22662266
*/
22672267
async getUserIdentities(): Promise<
22682268
| {
2269-
data: {
2270-
identities: UserIdentity[]
2271-
}
2272-
error: null
2269+
data: {
2270+
identities: UserIdentity[]
22732271
}
2272+
error: null
2273+
}
22742274
| { data: null; error: AuthError }
22752275
> {
22762276
try {
@@ -2395,9 +2395,9 @@ export default class GoTrueClient {
23952395
*/
23962396
async unlinkIdentity(identity: UserIdentity): Promise<
23972397
| {
2398-
data: {}
2399-
error: null
2400-
}
2398+
data: {}
2399+
error: null
2400+
}
24012401
| { data: null; error: AuthError }
24022402
> {
24032403
try {
@@ -3155,14 +3155,14 @@ export default class GoTrueClient {
31553155
| Exclude<MFAVerifyParams, MFAVerifyWebauthnParams>
31563156
/** Exclude out the webauthn params from here because we're going to need to serialize them in the response */
31573157
| Prettify<
3158-
StrictOmit<MFAVerifyWebauthnParams, 'webauthn'> & {
3159-
webauthn: Prettify<
3160-
StrictOmit<MFAVerifyWebauthnParamFields['webauthn'], 'credential_response'> & {
3161-
credential_response: PublicKeyCredentialJSON
3162-
}
3163-
>
3164-
}
3165-
>,
3158+
StrictOmit<MFAVerifyWebauthnParams, 'webauthn'> & {
3159+
webauthn: Prettify<
3160+
StrictOmit<MFAVerifyWebauthnParamFields['webauthn'], 'credential_response'> & {
3161+
credential_response: PublicKeyCredentialJSON
3162+
}
3163+
>
3164+
}
3165+
>,
31663166
/* Exclude challengeId because the backend expects snake_case, and exclude factorId since it's passed in the path params */
31673167
'challengeId' | 'factorId'
31683168
> & {
@@ -3171,18 +3171,18 @@ export default class GoTrueClient {
31713171
challenge_id: params.challengeId,
31723172
...('webauthn' in params
31733173
? {
3174-
webauthn: {
3175-
...params.webauthn,
3176-
credential_response:
3177-
params.webauthn.type === 'create'
3178-
? serializeCredentialCreationResponse(
3179-
params.webauthn.credential_response as RegistrationCredential
3180-
)
3181-
: serializeCredentialRequestResponse(
3182-
params.webauthn.credential_response as AuthenticationCredential
3183-
),
3184-
},
3185-
}
3174+
webauthn: {
3175+
...params.webauthn,
3176+
credential_response:
3177+
params.webauthn.type === 'create'
3178+
? serializeCredentialCreationResponse(
3179+
params.webauthn.credential_response as RegistrationCredential
3180+
)
3181+
: serializeCredentialRequestResponse(
3182+
params.webauthn.credential_response as AuthenticationCredential
3183+
),
3184+
},
3185+
}
31863186
: { code: params.code }),
31873187
}
31883188

@@ -3353,7 +3353,7 @@ export default class GoTrueClient {
33533353
for (const factor of user?.factors ?? []) {
33543354
data.all.push(factor)
33553355
if (factor.status === 'verified') {
3356-
;(data[factor.factor_type] as (typeof factor)[]).push(factor)
3356+
; (data[factor.factor_type] as (typeof factor)[]).push(factor)
33573357
}
33583358
}
33593359

@@ -3626,9 +3626,9 @@ export default class GoTrueClient {
36263626
} = {}
36273627
): Promise<
36283628
| {
3629-
data: { claims: JwtPayload; header: JwtHeader; signature: Uint8Array }
3630-
error: null
3631-
}
3629+
data: { claims: JwtPayload; header: JwtHeader; signature: Uint8Array }
3630+
error: null
3631+
}
36323632
| { data: null; error: AuthError }
36333633
| { data: null; error: null }
36343634
> {
@@ -3649,16 +3649,16 @@ export default class GoTrueClient {
36493649
raw: { header: rawHeader, payload: rawPayload },
36503650
} = decodeJWT(token)
36513651

3652-
if (!options?.allowExpired) {
3653-
// Reject expired JWTs should only happen if jwt argument was passed
3652+
// Only validate expiration if allowExpired is NOT true
3653+
if (options?.allowExpired !== true) {
36543654
validateExp(payload.exp)
36553655
}
36563656

36573657
const signingKey =
36583658
!header.alg ||
3659-
header.alg.startsWith('HS') ||
3660-
!header.kid ||
3661-
!('crypto' in globalThis && 'subtle' in globalThis.crypto)
3659+
header.alg.startsWith('HS') ||
3660+
!header.kid ||
3661+
!('crypto' in globalThis && 'subtle' in globalThis.crypto)
36623662
? null
36633663
: await this.fetchJwk(header.kid, options?.keys ? { keys: options.keys } : options?.jwks)
36643664

0 commit comments

Comments
 (0)