GitHub API Token expires when I host the web site

36 Views Asked by At

I'm making a web page to display GitHub repositories, but when I host my web site my GitHub API token gets expired., but when I'm running my project locally it works well without any errors. Can someone help?

function getRepositories(username) {
    const searchQuery = $('#searchInput').val() || '';
    if (!username) {
        console.error('No username provided.');
        return;
    }

    const apiUrl = `https://api.github.com/search/repositories?q=${searchQuery}+user:${username}&page=${currentPage}&per_page=${perPage}`;
    const headers = accessToken ? { 'Authorization': `Bearer ${accessToken}` } : {};

    $('#loader').show();

    $.ajax({
        url: apiUrl,
        method: 'GET',
        headers: headers,
        success: function (data, status) {
            if (status === 'success') {
                if (data.items.length > 0) {
                    displayRepositories(data.items);
                    displayPagination(data.total_count);
                } else {
                    displayError('No repositories found for the provided username.');
                }
            } else {
                console.error('Failed to fetch repositories');
                displayError('Error fetching repositories. Please try again later.');
            }
        },
        error: function (error) {
            console.error('Error fetching repositories:', error.statusText);
            displayError('Username not found. Refresh the page.');
        },
        complete: function () {
            $('#loader').hide();
        }
    });
}

I tried to generate new token and remove the old one's but still same issue is encountered. It is getting expired when I update my code in GitHub repository.

0

There are 0 best solutions below