on master help sign in
flows: look at GET params instead of window object

Unlike the window.flow approach, this will actually work in the real world. Also means we can't do the callbacks though.

commit5a7d61bdadd1382b1f699d08f427d41103c08d0c authorfang <git@fang.io> dateWed 24 Feb 2021, 21:01 (6 years ago) parent8d8b291
2 files changed+18−15
src/lib/flowCommand.js+18−12 src/views/flows/JustInvite.js−3
src/lib/flowCommand.js+18−12
@@ -2,28 +2,32 @@ import ob from 'urbit-ob';
22
33import { ensurePatFormat } from 'form/formatters';
44
5−// looks into the window context to find a "flow command", an object indicating
6−// if bridge is to be used for one specific flow.
7−// expects to find objects of the following shape, varying by kind:
5+// looks into the GET parameters and attempts to construct a "flow" object,
6+// which would indicate bridge is to be used for one specific flow.
7+// expects to find any of the following sets of parameters, varying by kind.
88//
9−// { kind: 'invite',
10−// as: '~ship', // who to send the invite as
11−// ship: '~ship', // what planet to send as the invite
12−// email: 'ex@amp.le' // email to send the invite code to
13−// }
9+// ? kind = invite
10+// & as = ~ship // who to send the invite as
11+// & ship = ~ship // what planet to send as the invite
12+// & email = ex@amp.le // email to send the invite code to
1413//
15−// you may optionally include .success() and .failure(reason) callbacks.
1614
1715const COMMANDS = {
1816 INVITE: 'invite',
1917};
2018
2119const useFlowCommand = () => {
22− let flow = window.flow;
20+ let flow = {};
21+ window.location.search
22+ .substr(1)
23+ .split('&')
24+ .forEach(arg => {
25+ if ('' === arg) return;
26+ const pam = arg.split('=');
27+ flow[pam[0]] = pam.length <= 1 ? true : decodeURIComponent(pam[1]);
28+ });
2329
2430 if (typeof flow === 'object') {
25− flow.success = flow.success || (() => {});
26− flow.failure = flow.failure || (() => {});
2731 switch (flow.kind) {
2832 case COMMANDS.INVITE:
2933 flow.as = ensurePatFormat(flow.as);
@@ -36,6 +40,8 @@ const useFlowCommand = () => {
3640 //
3741 default:
3842 console.log('unrecognized kind of flow:', flow.kind);
43+ // eslint-disable-next-line no-fallthrough
44+ case undefined:
3945 flow = null;
4046 break;
4147 }
src/views/flows/JustInvite.js−3
@@ -168,12 +168,9 @@ export default function JustInvite({ className, resetActivateRouter }) {
168168 //NOTE we could chuck a "pls join group-name" message in here
169169 await sendMail(_email, ticket, flow.as, '', rawTx);
170170 setProgress(1);
171−
172− flow.success();
173171 } catch (error) {
174172 // some generic error
175173 setGeneralError(error);
176− flow.failure(error);
177174 }
178175 }, [
179176 wallet,