Skip to content

Commit

Permalink
chore(auth): allow user refetch (nuxt-modules#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiblett1000 committed Mar 7, 2023
1 parent 824de23 commit 0a13546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/runtime/composables/useStrapiAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useStrapiAuth = () => {
}

const fetchUser = async (): Promise<Ref<StrapiUser>> => {
if (token.value && !user.value) {
if (token.value) {
try {
user.value = await client('/users/me', { params: config.strapi.auth, headers: { Authorization: `Bearer ${token.value}` } })
} catch (e) {
Expand Down
9 changes: 7 additions & 2 deletions src/runtime/strapi.plugin.ts
Original file line number Diff line number Diff line change
@@ -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()
}
})

0 comments on commit 0a13546

Please sign in to comment.