N
Nuxtβ€’10mo ago
PlayTexX

Error 500 on fetch user, but API returns me data

Hello, I have 500 error, but I dont know why because the API call is good 500 [GET] "https://localhost:9001/api/user": <no response> fetch failed at async $fetchRaw2 (./node_modules/ofetch/dist/shared/ofetch.00501375.mjs:228:14) at async $fetch2 (./node_modules/ofetch/dist/shared/ofetch.00501375.mjs:261:15) at async Module.useApiFetch (./composables/useApiFetch.ts:20:10) at async Proxy.fetchUser (./stores/authStore.ts:34:24) at async ./plugins/loadUser.ts:10:85 at async setup (./virtual:nuxt:/home/thibaut/projects/nuxt-3/.nuxt/plugins/server.mjs:40:116) at async Object.callAsync (./node_modules/unctx/dist/index.mjs:72:16) at async applyPlugin (./node_modules/nuxt/dist/app/nuxt.js:116:25) at async executePlugin (./node_modules/nuxt/dist/app/nuxt.js:153:9) Here is the method called in a loadUser plugin
import { useAuthStore } from "~/stores/authStore"

export default defineNuxtPlugin(async (nuxtApp) => {
// console.log('loadUser')
const auth = useAuthStore()
// console.log('isloggedIn', auth.isLoggedIn)
if (!auth.isLoggedIn) {
// console.log('fetchUser')
await auth.fetchUser()
}
})
import { useAuthStore } from "~/stores/authStore"

export default defineNuxtPlugin(async (nuxtApp) => {
// console.log('loadUser')
const auth = useAuthStore()
// console.log('isloggedIn', auth.isLoggedIn)
if (!auth.isLoggedIn) {
// console.log('fetchUser')
await auth.fetchUser()
}
})
async fetchUser() {
const response = await useApiFetch('/user', {
method: 'GET'
})

console.log('RESPONSE', response)
this.user = response as UserInterface
},
async fetchUser() {
const response = await useApiFetch('/user', {
method: 'GET'
})

console.log('RESPONSE', response)
this.user = response as UserInterface
},
Here is the console : GET http://localhost:3000/ 500 (Internal Server Error) devtools.client.mjs?v=83be3009:51 ✨ Nuxt DevTools Press Shift + Alt + D to open DevTools authStore.ts:50 RESPONSE {id: 2, email: '[email protected]', scope: Array(2)} chunk-L5BJSZYY.js?v=83be3009:2898 <Suspense> is an experimental feature and its API will likely change. backend.js:3301 🍍 "auth" store installed πŸ†•
1 Reply
PlayTexX
PlayTexXOPβ€’10mo ago
Okay, I added NODE_TLS_REJECT_UNAUTHORIZED=0 in .env and now it works
Want results from more Discord servers?
Add your server