Skip to content

not sending auth when it calls the second time. #13

@ghost

Description

Hi,

here's whats happening:

  1. Calls my API (fails with 401)
  2. Calls the refresh token api (success with new token)
  3. Calls my API again (fails because no new auth token sent)

I have enabled "authorizeRequest" - same as the example on medium.com

here's my config:
let config = { // (Required) Prepare fetch request for renewing new access token createAccessTokenRequest: (refreshToken) => { let refrehfd = new FormData(); refrehfd.append("refresh", refreshToken) return new Request(${DJ_API_URL}/project/refresh`, {
method: 'POST',
body:refrehfd
})
},

// (Required) Parses access token from access token response
parseAccessToken: (json) => {
return json.json().then(json => json.access)
.then(json => console.log("access",json.access))
.then(json => localStorage.setItem("access",json.access));

},
// (Required) Defines whether interceptor will intercept this request or just let it pass through
shouldIntercept: (request) => true,

// (Required) Defines whether access token will be invalidated after this response
shouldInvalidateAccessToken: (response) => true,

// When set, response which invalidates token will be resolved after the token has been renewed
// in effect, token will be loaded in sync with response, otherwise renew will run async to response
shouldWaitForTokenRenewal: true,

// Checks if response should be considered unauthorized (by default only 401 responses are
// considered unauthorized). Override this method if you need to trigger token renewal for
// other response statuses. Check API reference for helper method which defines default behaviour
isResponseUnauthorized: (response) => true,

// (Required) Adds authorization for intercepted requests
authorizeRequest: (request, access) => {
request.headers.set('Authorization', Bearer ${access});
return request;
},

// Number of retries after initial request was unauthorized
fetchRetryCount: 1,

// Event invoked when access token has changed
onAccessTokenChange: null,

// Event invoked when response is resolved
onResponse: null,
}

configure(config);
// here you provide tokens obtained from your Authorization Server
authorize(localStorage.getItem('refresh'), localStorage.getItem('access'));
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions