diff --git a/src/components/NewChallenge.js b/src/components/NewChallenge.js index a25229d..087810b 100644 --- a/src/components/NewChallenge.js +++ b/src/components/NewChallenge.js @@ -6,6 +6,7 @@ import injectIntl from '../utils/injectIntl'; import Header from './Header'; +import authenticate from '../utils/authenticate'; import randomId from '../utils/randomId'; import challengeExpiry from '../utils/challengeExpiry'; @@ -37,12 +38,14 @@ class NewChallenge extends React.Component { const expires = expiryFromSelect(this.expiresField); const mode = this.difficultyField.value; - this.props.base.post( - `challenges/${challengeId}`, { data: { name, expires, mode } } - ).then( - () => this.setState({ challengeId, name }), - () => this.setState(this.errorFor('challenges.errors.starting')) - ); + authenticate(this.props.base, () => { + this.props.base.post( + `challenges/${challengeId}`, { data: { name, expires, mode } } + ).then( + () => this.setState({ challengeId, name }), + () => this.setState(this.errorFor('challenges.errors.starting')) + ); + }); } else { this.setState(this.errorFor('challenges.errors.missingName')); } diff --git a/src/components/__tests__/NewChallenge.test.js b/src/components/__tests__/NewChallenge.test.js index 22fafa4..316f1b6 100644 --- a/src/components/__tests__/NewChallenge.test.js +++ b/src/components/__tests__/NewChallenge.test.js @@ -18,7 +18,10 @@ it('render a name field', () => { it('triggers onSubmit when submitting', () => { const promise = Promise.resolve(); - const base = { post: jest.fn().mockReturnValue(promise) }; + const base = { + post: jest.fn().mockReturnValue(promise), + onAuth: cb => cb({ uid: 'abc' }) + }; const wrapper = mountWithIntl( @@ -62,7 +65,10 @@ it('does not submit if the name is blank', () => { it('shows an error when the post fails', () => { const promise = Promise.reject(); - const base = { post: jest.fn().mockReturnValue(promise) }; + const base = { + post: jest.fn().mockReturnValue(promise), + onAuth: cb => cb({ uid: 'abc' }) + }; const wrapper = mountWithIntl(