Skip to content

Commit

Permalink
version 2.1.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmantz committed Jul 22, 2016
1 parent 9d09814 commit 567e837
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
20 changes: 10 additions & 10 deletions dist/redux-oidc.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-oidc",
"version": "2.0.2-beta.1",
"version": "2.1.0-beta.1",
"description": "A package for managing OpenID Connect authentication in redux apps",
"main": "dist/redux-oidc.js",
"scripts": {
Expand Down Expand Up @@ -60,12 +60,10 @@
"webpack": "^1.12.14",
"webpack-node-externals": "^1.2.0"
},
"dependencies": {
"oidc-client": "1.1.0-beta.3"
},
"peerDependencies": {
"react": ">=0.14.0",
"immutable": ">=3.6.0"
"immutable": ">=3.6.0",
"oidc-client": ">=1.1.0-beta.3"
},
"browserify": {
"transform": [
Expand Down
10 changes: 8 additions & 2 deletions src/CallbackComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { redirectSuccess } from './actions';

class CallbackComponent extends React.Component {
static propTypes = {
successCallback: PropTypes.func.isRequired
successCallback: PropTypes.func.isRequired,
errorCallback: PropTypes.func,
};

static contextTypes = {
Expand All @@ -24,7 +25,12 @@ class CallbackComponent extends React.Component {

onRedirectError = (error) => {
localStorage.removeItem(STORAGE_KEY);
throw new Error(`Error handling redirect callback: ${error.message}`);

if (this.props.errorCallback) {
this.props.errorCallback(error);
} else {
throw new Error(`Error handling redirect callback: ${error.message}`);
}
};

get defaultContent() {
Expand Down
17 changes: 15 additions & 2 deletions tests/callbackComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('<CallbackComponent />', () => {
let oldStorage;
let removeItemStub;
let successCallbackStub;
let errorCallbackStub;
let component;

beforeEach(() => {
Expand All @@ -28,12 +29,13 @@ describe('<CallbackComponent />', () => {
then: thenStub
});
successCallbackStub = sinon.stub();
errorCallbackStub = sinon.stub();

userManagerMock = {
signinRedirectCallback: signinRedirectCallbackStub
};

props = { successCallback: successCallbackStub };
props = { successCallback: successCallbackStub, errorCallback: errorCallbackStub };

contextMock = {
userManager: userManagerMock
Expand Down Expand Up @@ -69,9 +71,20 @@ describe('<CallbackComponent />', () => {
expect(successCallbackStub.calledWith(user)).toEqual(true);
});

it('should handle redirect errors correctly', () => {
it('should call the redirect error callback when provided', () => {
const error = { message: 'error'};

component.onRedirectError(error);

expect(errorCallbackStub.calledWith(error)).toEqual(true);
});

it('should throw an error when no error callback has been provided', () => {
const error = { message: 'error' };

props = { successCallback: successCallbackStub };
component = new CallbackComponent(props);

expect(() => component.onRedirectError(error)).toThrow(/error/);
expect(removeItemStub.calledWith(STORAGE_KEY)).toEqual(true);
});
Expand Down

0 comments on commit 567e837

Please sign in to comment.