I'm trying to fetch data from api, as always i need to secure my token that backend given. Using useRuntimeConfig that documentation of Nuxt given. But This always getting undefined value of token.
<script setup lang="ts">
interface User {
nama: string;
}
const pending = ref(true)
const data = ref < User > ()
onMounted(async() => {
const response = await fetch('/api/users', {
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${useRuntimeConfig().TOKEN}`,
},
})
const users = await response.json()
data.value = users
pending.value = false
})
</script>
Get solution that can store data from .env
useRuntimeConfigin a variable first?