From ddfba2e3ac3fa478557f4277d5f2a369c829aa4d Mon Sep 17 00:00:00 2001 From: jiblett1000 Date: Sun, 5 Mar 2023 10:33:59 -0800 Subject: [PATCH] allow user refetch --- src/runtime/composables/useStrapiAuth.ts | 2 +- src/runtime/strapi.plugin.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/runtime/composables/useStrapiAuth.ts b/src/runtime/composables/useStrapiAuth.ts index 042ffda2..2a4e5047 100644 --- a/src/runtime/composables/useStrapiAuth.ts +++ b/src/runtime/composables/useStrapiAuth.ts @@ -33,7 +33,7 @@ export const useStrapiAuth = () => { } const fetchUser = async (): Promise> => { - if (token.value && !user.value) { + if (token.value) { try { user.value = await client('/users/me', { params: config.strapi.auth }) } catch (e) { diff --git a/src/runtime/strapi.plugin.ts b/src/runtime/strapi.plugin.ts index 2225136e..4ff2ec8d 100644 --- a/src/runtime/strapi.plugin.ts +++ b/src/runtime/strapi.plugin.ts @@ -1,8 +1,13 @@ import { defineNuxtPlugin } from '#app' import { useStrapiAuth } from './composables/useStrapiAuth' +import { useStrapiUser } from './composables/useStrapiUser' export default defineNuxtPlugin(async () => { - const { fetchUser } = useStrapiAuth() + const user = useStrapiUser() - await fetchUser() + if (!user.value) { + const { fetchUser } = useStrapiAuth() + + await fetchUser() + } })