I'm encountering an issue where I make an API request to get a token and try to use it in another function located in a separate file. However, when I export the token from one file to another, it does not work as expected. The 'activate user' method is unable to read the token.
Here is my code in one file:
class User {
user_T= ''
getaccessToken(){
cy.request({
method: 'POST',
url: 'url',
form: true,
body: {
"username": ...,
"password": ....
}
})
.then(response => {
return this.user_T = response.body.Token;
})
}
}
export default new User
The other file contains:
import User from './user'
const token= new User()
it.only('activate user', () => {
cy.request({
method: "POST",
url: 'url/activate',
headers: {
'Authorization' : 'Bearer ' + token.user_T,
},
body:{
"test": 'test'
}
})
})