Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust client options to send credentials when needed #790

Conversation

colefichter
Copy link
Contributor

Check List

  • Tests has been run in packages where changes made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Note: the build instructions in the contribution guide are not working for me, so I can't build/run/test this change myself. Sorry about that!

Issue Reference this PR resolves

Original request here: #788

Description of Changes Made (if issue reference is not provided)

The Fetch API supports a credentials option to control the session cookies sent along with a request. By adjusting the Cube.js Client to support this option, we will be able to route our cube queries through a different sub-domain.

For example. If your site is running at secure.mydomain.com and your API calls need to go to api.mydomain.com it can be handy to pass the cookies over in the cross-domain API call. In order to support such a request pattern, the cube client must allow us to set credentials: 'include' when calling fetch().

Copy link
Member

@paveltiunov paveltiunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Cole! Thanks for contributing this! Overall looks great! Could you please adjust default values and also fix linter and tests.

@@ -2,10 +2,11 @@ import fetch from 'cross-fetch';
import 'url-search-params-polyfill';

class HttpTransport {
constructor({ authorization, apiUrl, headers = {} }) {
constructor({ authorization, apiUrl, headers = {}, credentials = 'same-origin' }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave default value to fetch itself and just remove 'same-origin'.

@@ -25,10 +25,12 @@ class CubejsApi {
this.apiToken = apiToken;
this.apiUrl = options.apiUrl || API_URL;
this.headers = options.headers || {};
this.credentials = options.credentials || 'same-origin';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@paveltiunov
Copy link
Member

@colefichter Looks great! The only thing in index.d.ts credentials field is required however it's optional. Could you please fix it and we're good to merge! Thanks!

@paveltiunov paveltiunov merged commit 5203f6c into cube-js:master Jul 4, 2020
@rpaik rpaik added the pr:community Contribution from Cube.js community members. label Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:community Contribution from Cube.js community members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants