Skip to content

Commit a1c8039

Browse files
authored
Merge pull request #40 from kaleido-io/fetch
add credentials to fetch requests
2 parents 838b5e8 + 5270f3a commit a1c8039

File tree

9 files changed

+46
-12
lines changed

9 files changed

+46
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "firefly-ui",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"private": true,
55
"dependencies": {
66
"@material-ui/core": "^4.11.4",

src/App.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
IStatus,
3939
} from './interfaces';
4040
import ReconnectingWebsocket from 'reconnecting-websocket';
41+
import { fetchWithCredentials } from './utils';
4142

4243
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
4344
const history = createBrowserHistory({
@@ -118,7 +119,10 @@ function App(): JSX.Element {
118119
const [lastEvent, setLastEvent] = useState<any>();
119120

120121
useEffect(() => {
121-
Promise.all([fetch('/api/v1/namespaces'), fetch('/api/v1/status')])
122+
Promise.all([
123+
fetchWithCredentials('/api/v1/namespaces'),
124+
fetchWithCredentials('/api/v1/status'),
125+
])
122126
.then(async ([namespaceResponse, statusResponse]) => {
123127
if (namespaceResponse.ok && statusResponse.ok) {
124128
const status: IStatus = await statusResponse.json();

src/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright © 2021 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
export const fetchWithCredentials = (
18+
resource: string,
19+
options?: RequestInit
20+
): Promise<Response> => {
21+
return fetch(resource, { ...options, credentials: 'include' });
22+
};

src/views/Dashboard.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { NamespaceContext } from '../contexts/NamespaceContext';
3737
import { ApplicationContext } from '../contexts/ApplicationContext';
3838
import { RecentTransactions } from '../components/RecentTransactions/RecentTransactions';
3939
import { FilterSelect } from '../components/FilterSelect';
40+
import { fetchWithCredentials } from '../utils';
4041

4142
export const Dashboard: React.FC = () => {
4243
const classes = useStyles();
@@ -76,14 +77,14 @@ export const Dashboard: React.FC = () => {
7677
}
7778

7879
Promise.all([
79-
fetch(`/api/v1/network/organizations?limit=100`),
80-
fetch(
80+
fetchWithCredentials(`/api/v1/network/organizations?limit=100`),
81+
fetchWithCredentials(
8182
`/api/v1/namespaces/${selectedNamespace}/data?limit=200${createdFilterString}`
8283
),
83-
fetch(
84+
fetchWithCredentials(
8485
`/api/v1/namespaces/${selectedNamespace}/messages?limit=200${createdFilterString}`
8586
),
86-
fetch(
87+
fetchWithCredentials(
8788
`/api/v1/namespaces/${selectedNamespace}/transactions?limit=200&created=>=${dayjs()
8889
.subtract(24, 'hours')
8990
.unix()}${createdFilterString}`

src/views/Data/Data.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { NamespaceContext } from '../../contexts/NamespaceContext';
3232
import { ApplicationContext } from '../../contexts/ApplicationContext';
3333
import { FilterSelect } from '../../components/FilterSelect';
3434
import { DataDetails } from './DataDetails';
35+
import { fetchWithCredentials } from '../../utils';
3536

3637
const PAGE_LIMITS = [10, 25];
3738

@@ -106,7 +107,7 @@ export const Data: React.FC = () => {
106107
createdFilterString = `&created=>=${dayjs().subtract(7, 'days').unix()}`;
107108
}
108109

109-
fetch(
110+
fetchWithCredentials(
110111
`/api/v1/namespaces/${selectedNamespace}/data?limit=${rowsPerPage}&skip=${
111112
rowsPerPage * currentPage
112113
}${createdFilterString}`

src/views/Messages/MessageDetails.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import clsx from 'clsx';
3535
import { NamespaceContext } from '../../contexts/NamespaceContext';
3636
import { useHistory } from 'react-router-dom';
3737
import Highlight from 'react-highlight';
38+
import { fetchWithCredentials } from '../../utils';
3839

3940
interface Props {
4041
message: IMessage;
@@ -65,10 +66,10 @@ export const MessageDetails: React.FC<Props> = ({ message, open, onClose }) => {
6566
useEffect(() => {
6667
setLoading(true);
6768
Promise.all([
68-
fetch(
69+
fetchWithCredentials(
6970
`/api/v1/namespaces/${selectedNamespace}/batches/${message.batchID}`
7071
),
71-
fetch(
72+
fetchWithCredentials(
7273
`/api/v1/namespaces/${selectedNamespace}/messages/${message.header.id}?data`
7374
),
7475
])

src/views/Messages/Messages.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { ApplicationContext } from '../../contexts/ApplicationContext';
4141
import { DataViewSwitch } from '../../components/DataViewSwitch';
4242
import { useHistory } from 'react-router-dom';
4343
import { FilterSelect } from '../../components/FilterSelect';
44+
import { fetchWithCredentials } from '../../utils';
4445

4546
const PAGE_LIMITS = [10, 25];
4647

@@ -84,7 +85,7 @@ export const Messages: React.FC = () => {
8485
createdFilterString = `&created=>=${dayjs().subtract(7, 'days').unix()}`;
8586
}
8687

87-
fetch(
88+
fetchWithCredentials(
8889
`/api/v1/namespaces/${selectedNamespace}/messages?limit=${rowsPerPage}&skip=${
8990
rowsPerPage * currentPage
9091
}${createdFilterString}`

src/views/Transactions/TransactionDetails.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
CardContent,
3333
makeStyles,
3434
} from '@material-ui/core';
35+
import { fetchWithCredentials } from '../../utils';
3536

3637
export const TransactionDetails: React.FC = () => {
3738
const history = useHistory();
@@ -55,7 +56,9 @@ export const TransactionDetails: React.FC = () => {
5556

5657
useEffect(() => {
5758
setLoading(true);
58-
fetch(`/api/v1/namespaces/${selectedNamespace}/transactions/${id}`)
59+
fetchWithCredentials(
60+
`/api/v1/namespaces/${selectedNamespace}/transactions/${id}`
61+
)
5962
.then(async (response) => {
6063
if (response.ok) {
6164
setTransaction(await response.json());

src/views/Transactions/Transactions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { ApplicationContext } from '../../contexts/ApplicationContext';
3939
import { DataTimeline } from '../../components/DataTimeline/DataTimeline';
4040
import { DataViewSwitch } from '../../components/DataViewSwitch';
4141
import { FilterSelect } from '../../components/FilterSelect';
42+
import { fetchWithCredentials } from '../../utils';
4243

4344
const PAGE_LIMITS = [10, 25];
4445

@@ -114,7 +115,7 @@ export const Transactions: React.FC = () => {
114115
createdFilterString = `&created=>=${dayjs().subtract(7, 'days').unix()}`;
115116
}
116117

117-
fetch(
118+
fetchWithCredentials(
118119
`/api/v1/namespaces/${selectedNamespace}/transactions?limit=${rowsPerPage}&skip=${
119120
rowsPerPage * currentPage
120121
}${createdFilterString}`

0 commit comments

Comments
 (0)