Skip to content

Commit 8a4da46

Browse files
committed
fix: Use access token JTI for cache key
1 parent 5e986ce commit 8a4da46

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/utils/auth.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ export const authOptions: AuthOptions = {
4242
}
4343

4444
// Access token is expired :(
45-
if (Date.now() / 1000 > parseJwt(token.accessToken).exp) {
46-
const tokenId = parseJwt(token.refreshToken).jti;
45+
const accessTokenPayload = parseJwt(token.accessToken);
46+
if (Date.now() / 1000 > accessTokenPayload.exp) {
47+
const tokenId = accessTokenPayload.jti;
4748

4849
// Obtain new token pair and new profile data
4950
if (!refreshTokenPromiseCache[tokenId]) {
@@ -52,7 +53,7 @@ export const authOptions: AuthOptions = {
5253
`${process.env.NEXT_PUBLIC_API_URL}/auth/token/`,
5354
{
5455
method: 'POST',
55-
headers: { 'Content-Type': 'application/json', },
56+
headers: { 'Content-Type': 'application/json' },
5657
body: JSON.stringify({ refresh: token.refreshToken }),
5758
},
5859
)

0 commit comments

Comments
 (0)