Skip to content

Commit

Permalink
fix: refresh token behavior (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
felippepuhle committed Aug 18, 2020
1 parent 6670000 commit f24cb95
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,17 @@ export default function authMiddleware(opts?: AuthMiddlewareOpts): Middleware {
}

return tokenRefreshInProgress.then((newToken) => {
if (!newToken && !allowEmptyToken) {
throw new RRNLAuthMiddlewareError('Empty token');
}

const newReq = req.clone();
newReq.fetchOpts.headers[header] = `${prefix}${newToken}`;
if (newToken) {
newReq.fetchOpts.headers[header] = `${prefix}${newToken}`;
} else {
delete newReq.fetchOpts.headers[header];
}

return next(newReq); // re-run query with new token
});
}
Expand Down

0 comments on commit f24cb95

Please sign in to comment.