Hello all, I'm a beginner with Vue so please bear with me :)
I am facing a challenge where I have a function that retrieves user attributes and based on those attributes, I need to run a GraphQL query in another function. Both functions are under the 'methods' section and are called in the 'created' lifecycle. I tried storing the value in a variable and rendering it in the DOM, but I am unable to pass it to the desired function. I even attempted running the functions in different lifecycle hooks, but that didn't solve the issue.
export default defineComponent({
name: 'IndexPage',
data: function() {
return {
token: '',
redirectUrl: '',
authUser: ''
}
},
methods:{
async setUser() {
this.authUser = authUser
},
async getAtt() {
Auth.currentAuthenticatedUser()
.then(data => (this.authUser = data.attributes['custom:learn_url']))
.catch(err => console.log(err));
},
async getUrl() {
const id = this.authUser; // This is where i want the id to assign the authUser value
const learnUrl = await API.graphql({
variables: { id },
query: getLearnUrl
});
this.redirectUrl = learnUrl.data.getLearnUrl.learnUrl;
}
},
created() {
this.getAtt();
this.getUrl();
}
})