Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

iam working with token autentication
for some of endpoint need auth token and need to be included in header options..
but in static web browser doesnot show any of header options and for every endpoint iam getting an auth token error
i checked endpoints with other clients postman. it is working fine..
can add a feature for posting header option also to the static web browser views

You must be logged in to vote

After receiving the token from the backend, it should be saved in the browser's local storage for future authentication, as follows:

const authToken = response.headers.get('Authorization');
if (authToken) {
    localStorage.setItem('authToken', authToken);
}

Now, with every request, you will need to include the token in the header. You can do it as follows:

function fetchWithAuth(url, options = {}) {
    const authToken = localStorage.getItem('authToken'); 

    
    const headers = {
        ...options.headers,
        'Authorization': authToken ? authToken : '',
        'Content-Type': 'application/json', 
    };

    /
    return fetch(url, {
        ...options,
        headers,
    }…

Replies: 1 comment

Comment options

After receiving the token from the backend, it should be saved in the browser's local storage for future authentication, as follows:

const authToken = response.headers.get('Authorization');
if (authToken) {
    localStorage.setItem('authToken', authToken);
}

Now, with every request, you will need to include the token in the header. You can do it as follows:

function fetchWithAuth(url, options = {}) {
    const authToken = localStorage.getItem('authToken'); 

    
    const headers = {
        ...options.headers,
        'Authorization': authToken ? authToken : '',
        'Content-Type': 'application/json', 
    };

    /
    return fetch(url, {
        ...options,
        headers,
    });
}

Both are parts of the frontend.

please let me know if this worked.

You must be logged in to vote
0 replies
Answer selected by browniebroke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #9579 on July 06, 2025 14:47.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.