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 null 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
New contributor
Ahmad Muzaki SA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.