Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

javascript - Problems with page loading data on JS

I have a problem with my code, when the page is loading and the code is starting running The code works very fast, and even before it is enough to reach all the lines it already continues to run. What happens is that the page does not get the data disability and I'm not getting the users right way.

Here is my code:

 var users = [{}]
    getUsers();
    function getUsers() {
        const res = http.get('users/')
        .then(res => {
            users = res.data
        })
        .catch(function (error) {
            console.log(error);
        })
    }

mock.onPost('/api/auth/access-token').reply(config => {
    const data = JSON.parse(config.data);
    const { access_token } = data;
    
            try {
                const { id } = jwt.verify(access_token, jwtConfig.secret);
                const usersID = window.localStorage.getItem('usersId')
                const user = _.cloneDeep(users.find(_user => _user.uuid === usersID));
                delete user.password;
                const updatedAccessToken = jwt.sign({ id: user.uuid }, jwtConfig.secret, { expiresIn: jwtConfig.expiresIn });
    
                const response = {
                    user,
                    access_token: updatedAccessToken
                };
    
                return [200, response];
            } catch (e) {
                const error = 'Invalid access token detected';
                return [401, { error }];
            
        }
            
        
});

if you have an idea how to fix the code I will be very happy. Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...