Skip to content

Commit 416a325

Browse files
anjarupnikAnja
andauthored
fix(#947): only call refresh when auth token is expired (#1087)
* fix(refresh-token): only refresh when auth token is expired * fix(refresh-token): PR requested changes --------- Co-authored-by: Anja <anja@bookchoice.com>
1 parent 360f2dd commit 416a325

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/runtime/plugins/refresh-token.server.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ export default defineNuxtPlugin({
99
const { rawToken, rawRefreshToken, refreshToken, token, lastRefreshedAt }
1010
= useAuthState()
1111

12-
if (refreshToken.value && token.value) {
12+
if (refreshToken.value) {
1313
const provider = useTypedBackendConfig(useRuntimeConfig(), 'local')
1414

1515
const { path, method } = provider.refresh.endpoint
1616
const refreshRequestTokenPointer = provider.refresh.token.refreshRequestTokenPointer
1717

1818
// include header in case of auth is required to avoid 403 rejection
19-
const headers = new Headers({
20-
[provider.token.headerName]: token.value
21-
} as HeadersInit)
19+
const headers = token.value
20+
? new Headers({
21+
[provider.token.headerName]: token.value
22+
} as HeadersInit)
23+
: undefined
2224

2325
try {
2426
const response = await _fetch<Record<string, any>>(nuxtApp, path, {

0 commit comments

Comments
 (0)