Skip to content

Commit

Permalink
Respect showTerms option for passworless (auth0#1931)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Hobbs <steve.hobbs@auth0.com>
  • Loading branch information
saltukalakus and Steve Hobbs authored Oct 23, 2020
1 parent f15f898 commit 1b488a1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Array [
Immutable.Map {
"send": "code",
"mustAcceptTerms": false,
"showTerms": true,
},
]
`;
Expand All @@ -16,6 +17,7 @@ Array [
Immutable.Map {
"send": "code",
"mustAcceptTerms": true,
"showTerms": true,
},
]
`;
Expand All @@ -26,6 +28,7 @@ Array [
Immutable.Map {
"send": "code",
"mustAcceptTerms": false,
"showTerms": true,
},
]
`;
Expand All @@ -36,6 +39,7 @@ Array [
Immutable.Map {
"send": "code",
"mustAcceptTerms": false,
"showTerms": true,
},
]
`;
Expand All @@ -46,6 +50,40 @@ Array [
Immutable.Map {
"send": "link",
"mustAcceptTerms": false,
"showTerms": true,
},
]
`;

exports[`passwordless connection initPasswordless() calls initNS with showTerms:false when opts.showTerms is false 1`] = `
Array [
null,
Immutable.Map {
"send": "code",
"mustAcceptTerms": false,
"showTerms": false,
},
]
`;

exports[`passwordless connection initPasswordless() calls initNS with showTerms:true when opts.showTerms is true 1`] = `
Array [
null,
Immutable.Map {
"send": "code",
"mustAcceptTerms": false,
"showTerms": true,
},
]
`;

exports[`passwordless connection initPasswordless() calls initNS with showTerms:true when opts.showTerms is undefined 1`] = `
Array [
null,
Immutable.Map {
"send": "code",
"mustAcceptTerms": false,
"showTerms": true,
},
]
`;
Expand Down
17 changes: 16 additions & 1 deletion src/__tests__/connection/passwordless/passwordless.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ describe('passwordless connection', () => {
});
expectMockToMatch(mockFns.initNS, 1);
});
it('with showTerms:true when opts.showTerms is undefined', () => {
initPasswordless(null, {});
expectMockToMatch(mockFns.initNS, 1);
});
it('with showTerms:true when opts.showTerms is true', () => {
initPasswordless(null, {
showTerms: true
});
expectMockToMatch(mockFns.initNS, 1);
});
it('with showTerms:false when opts.showTerms is false', () => {
initPasswordless(null, {
showTerms: false
});
expectMockToMatch(mockFns.initNS, 1);
});
});
it('should load default location via options.defaultLocation', () => {
initPasswordless(null, {
Expand All @@ -89,7 +105,6 @@ describe('passwordless connection', () => {
expectMockToMatch(mockFns.get, 1);
});
});

describe('toggleTermsAcceptance()', () => {
it('should tset `termsAccepted` to false when `termsAccepted` is true', () => {
mockFns.get.mockReturnValue(true);
Expand Down
7 changes: 6 additions & 1 deletion src/connection/passwordless/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export function initPasswordless(m, opts) {
// TODO: validate opts
const send = opts.passwordlessMethod === 'link' ? 'link' : 'code';
const mustAcceptTerms = !!opts.mustAcceptTerms;
const showTerms = opts.showTerms === undefined ? true : !!opts.showTerms;

m = initNS(m, Map({ send, mustAcceptTerms }));
m = initNS(m, Map({ send, mustAcceptTerms, showTerms }));
if (opts.defaultLocation && typeof opts.defaultLocation === 'string') {
m = initLocation(m, opts.defaultLocation.toUpperCase());
} else {
Expand Down Expand Up @@ -104,6 +105,10 @@ export function isEmail(m) {
return c.isEmpty() ? undefined : c.get('strategy') === 'email';
}

export function showTerms(m) {
return get(m, 'showTerms', true);
}

export function mustAcceptTerms(m) {
return get(m, 'mustAcceptTerms', false);
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/passwordless/social_or_email_login_screen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Screen from '../../core/screen';
import EmailPane from '../../field/email/email_pane';
import SocialButtonsPane from '../../field/social/social_buttons_pane';
import PaneSeparator from '../../core/pane_separator';
import { mustAcceptTerms, termsAccepted } from '../../connection/passwordless/index';
import { mustAcceptTerms, termsAccepted, showTerms } from '../../connection/passwordless/index';
import { toggleTermsAcceptance } from '../../connection/passwordless/actions';
import { requestPasswordlessEmail } from '../../connection/passwordless/actions';
import { renderEmailSentConfirmation } from '../../connection/passwordless/email_sent_confirmation';
Expand Down Expand Up @@ -77,7 +77,7 @@ export default class SocialOrEmailLoginScreen extends Screen {

renderTerms(m, terms) {
const checkHandler = mustAcceptTerms(m) ? () => toggleTermsAcceptance(l.id(m)) : undefined;
return terms || mustAcceptTerms(m) ? (
return terms && showTerms(m) ? (
<SignUpTerms
showCheckbox={mustAcceptTerms(m)}
checkHandler={checkHandler}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PaneSeparator from '../../core/pane_separator';
import * as l from '../../core/index';

import { renderOptionSelection } from '../../field/index';
import { mustAcceptTerms, termsAccepted } from '../../connection/passwordless/index';
import { mustAcceptTerms, termsAccepted, showTerms } from '../../connection/passwordless/index';
import { toggleTermsAcceptance } from '../../connection/passwordless/actions';
import SignUpTerms from '../../connection/database/sign_up_terms';

Expand Down Expand Up @@ -68,7 +68,7 @@ export default class AskSocialNetworkOrPhoneNumber extends Screen {

renderTerms(m, terms) {
const checkHandler = mustAcceptTerms(m) ? () => toggleTermsAcceptance(l.id(m)) : undefined;
return terms || mustAcceptTerms(m) ? (
return terms && showTerms(m) ? (
<SignUpTerms
showCheckbox={mustAcceptTerms(m)}
checkHandler={checkHandler}
Expand Down

0 comments on commit 1b488a1

Please sign in to comment.