I created a process.env file in order to store a data to make api calls. I tried to define variables in my nuxt.config.js to use them in my vuex store but in config file I cant access them. Here is my code:
it’s my nuxt.config:
<code>export default {
// Target: https://go.nuxtjs.dev/config-target
target: 'static',
publicRuntimeConfig: {
clientId: process.env.CLIENT_ID || 'hi',
clientSecret: process.env.CLIENT_SECRET
},
}
</code>
<code>export default {
// Target: https://go.nuxtjs.dev/config-target
target: 'static',
publicRuntimeConfig: {
clientId: process.env.CLIENT_ID || 'hi',
clientSecret: process.env.CLIENT_SECRET
},
}
</code>
export default {
// Target: https://go.nuxtjs.dev/config-target
target: 'static',
publicRuntimeConfig: {
clientId: process.env.CLIENT_ID || 'hi',
clientSecret: process.env.CLIENT_SECRET
},
}
store.js:
<code>const actions = {
async fetchData(context) {
const clientId = this.$config;
console.log(clientId);
try {
const apiEndpoint = 'https://www.udemy.com/api-2.0/courses/';
const response = await this.$axios.get(`curl -H "Authorization: Basic {BASE64_ENCODED(${this.$config.clientId}:${this.$config.clientSecret})}" ${apiEndpoint}`)
console.log(response.data);
} catch (error) {
} finally {
}
},}
</code>
<code>const actions = {
async fetchData(context) {
const clientId = this.$config;
console.log(clientId);
try {
const apiEndpoint = 'https://www.udemy.com/api-2.0/courses/';
const response = await this.$axios.get(`curl -H "Authorization: Basic {BASE64_ENCODED(${this.$config.clientId}:${this.$config.clientSecret})}" ${apiEndpoint}`)
console.log(response.data);
} catch (error) {
} finally {
}
},}
</code>
const actions = {
async fetchData(context) {
const clientId = this.$config;
console.log(clientId);
try {
const apiEndpoint = 'https://www.udemy.com/api-2.0/courses/';
const response = await this.$axios.get(`curl -H "Authorization: Basic {BASE64_ENCODED(${this.$config.clientId}:${this.$config.clientSecret})}" ${apiEndpoint}`)
console.log(response.data);
} catch (error) {
} finally {
}
},}
console.log(clientId) returns hi