Skip to content

Commit 0c475c8

Browse files
author
jhz
committed
added optional to set authorization header token
1 parent 6f9348c commit 0c475c8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/components/fetch-wrapper.jsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function withFetching(WrappedComponent, props) {
1010
constructor(props) { // eslint-disable-line no-shadow
1111
super(props);
1212
this.state = {};
13-
this.xhr = this.createRequest(props.filePath);
13+
this.xhr = this.createRequest(props.filePath, props.authToken);
1414
}
1515

1616
componentDidMount() {
@@ -28,9 +28,12 @@ function withFetching(WrappedComponent, props) {
2828
this.abort();
2929
}
3030

31-
createRequest(path) {
31+
createRequest(path, authToken=null) {
3232
let xhr = new XMLHttpRequest();
3333

34+
if(authToken !== null)
35+
xhr.setRequestHeader('Authorization', authToken);
36+
3437
if ('withCredentials' in xhr) {
3538
// XHR for Chrome/Firefox/Opera/Safari.
3639
xhr.open('GET', path, true);

src/components/file-viewer.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class FileViewer extends Component {
8585
FileViewer.propTypes = {
8686
fileType: PropTypes.string.isRequired,
8787
filePath: PropTypes.string.isRequired,
88+
authToken: PropTypes.string,
8889
onError: PropTypes.func,
8990
errorComponent: PropTypes.element,
9091
unsupportedComponent: PropTypes.element,

0 commit comments

Comments
 (0)