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

Fix browser-cookies error in clientOnly mode #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/actions/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export function configure(endpoint={}, settings={}) {

let {authRedirectPath, authRedirectHeaders} = getRedirectInfo(window.location);

mustResetPassword = authRedirectHeaders.reset_password ? true : false
firstTimeLogin = authRedirectHeaders
.account_confirmation_success ? true : false

if (authRedirectPath) {
dispatch(push({pathname: authRedirectPath}));
}
Expand Down
18 changes: 11 additions & 7 deletions src/utils/client-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as C from "./constants";
import extend from "extend";
import fetch from "./fetch";
import parseEndpointConfig from "./parse-endpoint-config";
import {parseResponse} from "./handle-fetch-response";
import {setEndpointKeys} from "../actions/configure";
import {
getApiUrl,
Expand Down Expand Up @@ -95,18 +96,21 @@ export function applyConfig({dispatch, endpoint={}, settings={}, reset=false}={}

if (getCurrentSettings().initialCredentials) {
// skip initial headers check (i.e. check was already done server-side)
let {user, headers} = getCurrentSettings().initialCredentials;
let headers = getCurrentSettings().initialCredentials;
persistData(C.SAVED_CREDS_KEY, headers);
return Promise.resolve(user);
return fetch(`${getApiUrl(currentEndpointKey)}${currentEndpoint[currentEndpointKey].tokenValidationPath}`)
.then(response => {
return parseResponse(response,
() => (removeData(C.SAVED_CREDS_KEY)))
.then(({data}) => (data));
});
} else if (savedCreds) {
// verify session credentials with API
return fetch(`${getApiUrl(currentEndpointKey)}${currentEndpoint[currentEndpointKey].tokenValidationPath}`)
.then(response => {
if (response.status >= 200 && response.status < 300) {
return response.json().then(({ data }) => (data));
}
removeData(C.SAVED_CREDS_KEY);
return Promise.reject({reason: "No credentials."});
return parseResponse(response,
() => (removeData(C.SAVED_CREDS_KEY)))
.then(({data}) => (data));
});
} else {
return Promise.reject({reason: "No credentials."})
Expand Down
3 changes: 2 additions & 1 deletion src/utils/handle-fetch-response.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export function parseResponse (response) {
export function parseResponse (response, cb = () => {}) {
let json = response.json();
if (response.status >= 200 && response.status < 300) {
return json;
} else {
cb()
return json.then(err => Promise.reject(err));
}
}