{"size": 801, "ext": "js", "max_stars_repo_path": "src/api/refreshToken.js", "max_stars_repo_name": "tqcaoson/myShop", "max_stars_repo_stars_event_min_datetime": "2020-04-20T02:42:43.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-20T02:42:43.000Z", "max_issues_repo_path": "src/api/refreshToken.js", "max_issues_repo_name": "tqcaoson/myShop", "max_issues_repo_issues_event_min_datetime": "2021-05-11T06:59:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T17:43:29.000Z", "max_forks_repo_path": "src/api/refreshToken.js", "max_forks_repo_name": "tqcaoson/myShop", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 25.03125, "max_line_length": 61, "alphanum_fraction": 0.543071161}
import saveToken from './saveToken';
import getToken from './getToken';

const getNewToken = (token) => (
    fetch('http://localhost/app/refresh_token.php',
    {   
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            Accept: 'application/json'
        },
        body: JSON.stringify({ token })
    })
    .then(res => res.text())
);

const refreshToken = async () => {
    try {
        const token = await getToken();
        if (token === '' || token === 'TOKEN_KHONG_HOP_LE') {
            console.log('Chua co token');
        }
        const newToken = await getNewToken(token);
        await saveToken(newToken);
        console.log('TOKEN MOI: ' + newToken);
    } catch (e) {
        console.log(e);
    }
};

export default refreshToken;
