Skip to content

Commit

Permalink
More complete support for custom passwordless connections (#2105)
Browse files Browse the repository at this point in the history
* Better support custom passwordless connections

Update passwordless actions so that `login` can use custom passwordless connection

* Pass in required param

Co-authored-by: ISGPete <[email protected]>
  • Loading branch information
peter-isgfunds and ISGPete authored Mar 18, 2022
1 parent df60350 commit e7da750
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/connection/passwordless/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ function resendEmailError(id, error) {
swap(updateEntity, 'lock', id, setResendFailed);
}

function sendEmail(m, successFn, errorFn) {
const connections = l.connections(m, 'passwordless', 'email');
const connectionName =
connections.size > 0 && l.useCustomPasswordlessConnection(m)
? connections.first().get('name')
: 'email';
function getPasswordlessConnectionName(m, defaultPasswordlessConnection) {
const connections = l.connections(m, 'passwordless', defaultPasswordlessConnection);

return connections.size > 0 && l.useCustomPasswordlessConnection(m)
? connections.first().get('name')
: defaultPasswordlessConnection;
}

function sendEmail(m, successFn, errorFn) {
const params = {
connection: connectionName,
connection: getPasswordlessConnectionName(m, 'email'),
email: c.getFieldValue(m, 'email'),
send: send(m)
};
Expand All @@ -95,14 +97,8 @@ function sendEmail(m, successFn, errorFn) {

export function sendSMS(id) {
validateAndSubmit(id, ['phoneNumber'], m => {
const connections = l.connections(m, 'passwordless', 'sms');
const connectionName =
connections.size > 0 && l.useCustomPasswordlessConnection(m)
? connections.first().get('name')
: 'sms';

const params = {
connection: connectionName,
connection: getPasswordlessConnectionName(m, 'sms'),
phoneNumber: phoneNumberWithDiallingCode(m),
send: send(m)
};
Expand Down Expand Up @@ -139,10 +135,10 @@ export function logIn(id) {
...authParams
};
if (isEmail(m)) {
params.connection = 'email';
params.connection = getPasswordlessConnectionName(m, 'email');
params.email = c.getFieldValue(m, 'email');
} else {
params.connection = 'sms';
params.connection = getPasswordlessConnectionName(m, 'sms');
params.phoneNumber = phoneNumberWithDiallingCode(m);
}
swap(updateEntity, 'lock', id, l.setSubmitting, true);
Expand Down

0 comments on commit e7da750

Please sign in to comment.