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() + } })