Skip to content

Commit 443cc8a

Browse files
committed
fixed client authentication
1 parent 615b47f commit 443cc8a

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

packages/client/src/middleware/store.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { initialize as initializeAframe } from '../external/aframe';
77
import { initialize as initializeConnection } from '../external/connection';
88
import { initialize as initializeOmni } from '../external/omnisockets';
99
import { State } from '../interfaces';
10-
import { authenticateProcess, loadSecretProcess } from '../processes/authenticate.process';
10+
import { attemptAuthenticationProcess, loadSecretProcess } from '../processes/authenticate.process';
1111
import { connectProcess } from '../processes/connection.process';
1212

1313
const commandFactory = createCommandFactory<State>();
@@ -44,12 +44,7 @@ export const store = createStoreMiddleware<State>(async (store: Store<State>) =>
4444
initializeConnection(store);
4545
await initializeAframe(store);
4646
await connectProcess(store)({})
47-
48-
const secret = store.get(store.path('auth', 'secret'));
49-
50-
if (secret) {
51-
await authenticateProcess(store)({ secret });
52-
}
47+
await attemptAuthenticationProcess(store)({});
5348

5449
debug(store);
5550
});

packages/client/src/processes/authenticate.process.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ const setUnauthenticatedCommand = commandFactory(({ path }) => {
4444
];
4545
});
4646

47-
const authenticateCommand = commandFactory<{ secret: string }>(({ get, path, payload: { secret } }) => {
48-
authenticate({ role: 'presenter', secret });
49-
})
47+
const authenticateCommand = commandFactory(({ get, path }) => {
48+
const secret = get(path('auth', 'secret'));
49+
50+
if (secret) {
51+
authenticate({ role: 'presenter', secret });
52+
}
53+
});
5054

5155
export const loadSecretProcess = createProcess('load-secret', [ loadSecretCommand ])
5256
export const saveSecretProcess = createProcess('save-secret', [ saveSecretCommand ]);
5357
export const setSecretProcess = createProcess('set-secret', [ setSecretCommand ]);
5458
export const setUnauthenticatedProcess = createProcess('set-unauthenticated', [ setUnauthenticatedCommand ]);
5559
export const setAuthenticatedProcess = createProcess('set-authenticated', [ setAuthenticatedCommand ]);
5660
export const authenticateProcess = createProcess('authenticate', [ authenticateCommand ]);
61+
export const attemptAuthenticationProcess = createProcess('attempt-authentication', [ loadSecretCommand, authenticateCommand ])

packages/client/src/processes/connection.process.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const commandFactory = createCommandFactory<State>();
1010

1111
const setDisconnectedCommand = commandFactory(async ({ path }) => {
1212
return [
13-
replace(path('isConnected'), false)
13+
replace(path('isConnected'), false),
14+
replace(path('auth', 'isAuthenticated'), false)
1415
];
1516
});
1617

packages/client/src/widgets/authentication/Authentication.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export default factory(function Authentication({ middleware: { store: { get, pat
1717

1818
return (<div>
1919
<TextInput value={secret} onChange={(value) => { setSecret({ secret: String(value) }) }} placeholder="Secret" type="password" />
20-
<Control title="Authenticate" show={true} onClick={() => { authenticate({ secret }) }} />
20+
<Control title="Authenticate" show={true} onClick={() => { authenticate({}) }} />
2121
</div>);
2222
});

packages/client/src/widgets/menu/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default factory(function Menu({ middleware: { store: { get, path, executo
3737
<div classes={css.indentedContainer}>
3838
<Status value={isConnected} trueLabel="Connected" falseLabel="Disconnected" />
3939
<Status value={isAuthenticated} trueLabel="Authenticated" falseLabel="Not Authenticated" />
40-
{ isAuthenticated && <Status value={isPresenter} trueLabel="Presenter" falseLabel="Viewer" /> }
40+
{ isAuthenticated && <Status value={isPresenter} trueLabel="Presenting" falseLabel="Not Presenting" /> }
4141
</div>
4242
</Card>
4343
<Card title="Connection">

0 commit comments

Comments
 (0)