Skip to content

Commit

Permalink
Merge pull request #68 from mosmohamed/header_credentials
Browse files Browse the repository at this point in the history
Add credentials to fetch with cookies
  • Loading branch information
jonathanlloyd authored Sep 16, 2020
2 parents 2a12493 + 8c37673 commit fe82743
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
.cache/
.idea/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/pusher/push-notifications-web/compare/1.0.3...HEAD)
- Allow the fetch `credentials` option to be overidden in the default TokenProvider
implementation.

## [1.0.3](https://github.com/pusher/push-notifications-web/compare/1.0.2...1.0.3) - 2020-09-10
- Fix bug in SDK where we weren't waiting for custom Service Workers to become
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface TokenProviderOptions {
url: string;
queryParams?: { [key: string]: any };
headers?: { [key: string]: string };
credentials?: string;
}

export class TokenProvider implements ITokenProvider {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/do-request.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
export default function doRequest({ method, path, body = null, headers = {} }) {
export default function doRequest({
method,
path,
body = null,
headers = {},
credentials = 'same-origin',
}) {
const options = {
method,
headers,
credentials,
};

if (body !== null) {
Expand Down
4 changes: 3 additions & 1 deletion src/token-provider.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import doRequest from './do-request';

export default class TokenProvider {
constructor({ url, queryParams, headers } = {}) {
constructor({ url, queryParams, headers, credentials } = {}) {
this.url = url;
this.queryParams = queryParams;
this.headers = headers;
this.credentials = credentials;
}

async fetchToken(userId) {
Expand All @@ -16,6 +17,7 @@ export default class TokenProvider {
method: 'GET',
path: `${this.url}?${encodedParams}`,
headers: this.headers,
credentials: this.credentials,
};
let response = await doRequest(options);
return response;
Expand Down

0 comments on commit fe82743

Please sign in to comment.