From d314b86842aa791e858918ac7a3a8a5fcee82d08 Mon Sep 17 00:00:00 2001 From: manchenkoff Date: Thu, 18 Apr 2024 00:26:46 +0200 Subject: [PATCH 1/3] fix: reset user only when it expires --- src/runtime/httpFactory.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/httpFactory.ts b/src/runtime/httpFactory.ts index 092c9d8..349c074 100644 --- a/src/runtime/httpFactory.ts +++ b/src/runtime/httpFactory.ts @@ -147,7 +147,8 @@ export function createHttpClient(logger: ConsolaInstance): $Fetch { if ( response.status === 401 && - request.toString().endsWith(options.endpoints.user) + request.toString().endsWith(options.endpoints.user) && + user.value !== null ) { logger.warn( 'User session is not set in API or expired, resetting identity' From c88fbdfbcc2f27db1311da49fa0b407b44b41949 Mon Sep 17 00:00:00 2001 From: manchenkoff Date: Thu, 18 Apr 2024 00:27:42 +0200 Subject: [PATCH 2/3] fix: request identity once on plugin init --- src/runtime/plugin.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index 569f194..15655d1 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -1,5 +1,5 @@ import { FetchError } from 'ofetch'; -import { defineNuxtPlugin } from '#app'; +import { defineNuxtPlugin, useState } from '#app'; import { createHttpClient } from './httpFactory'; import { useSanctumUser } from './composables/useSanctumUser'; import { useSanctumConfig } from './composables/useSanctumConfig'; @@ -34,7 +34,14 @@ export default defineNuxtPlugin(async () => { const logger = createSanctumLogger(options.logLevel); const client = createHttpClient(logger); - if (user.value === null) { + const identityFetchedOnInit = useState( + 'sanctum.user.loaded', + () => false + ); + + if (user.value === null && identityFetchedOnInit.value === false) { + identityFetchedOnInit.value = true; + try { user.value = await client(options.endpoints.user); } catch (error) { From cc76b0e285bfd7970c39592c77cfa13203e394ba Mon Sep 17 00:00:00 2001 From: manchenkoff Date: Thu, 18 Apr 2024 01:25:25 +0200 Subject: [PATCH 3/3] fix: push main branch after bumping release version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index adc69e0..e56dbe7 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "test": "vitest run", "test:watch": "vitest watch", "validate": "npm run fmt:check && npm run lint && npm run types && npm run test", - "release": "npm run validate && npm run prepack && changelogen --release && npm publish" + "release": "npm run validate && npm run prepack && changelogen --release && npm publish && git push" }, "dependencies": { "@nuxt/kit": "^3.9.0",