Skip to content

Commit cc24d0f

Browse files
committed
Fix opening socket when not signed in
1 parent a30ba18 commit cc24d0f

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

packages/app/src/app/overmind/dependencies/overmind-graphql.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ type Http = {
3838
options?: Options;
3939
};
4040

41-
type Ws =
42-
| {
43-
endpoint: string;
44-
params?: () => { [key: string]: string | number | boolean };
45-
}
46-
| PhoenixSocket;
41+
type Ws = PhoenixSocket | null;
4742

4843
type Queries = {
4944
queries?: {
@@ -128,12 +123,14 @@ export const graphql: <T extends Queries>(
128123
return null;
129124
}
130125

126+
let wsClient: PhoenixSocket | null = null;
131127
function getWsClient(): PhoenixSocket | null {
132-
if (_ws) {
133-
return withAbsintheSocket.create(_ws);
128+
if (_ws && !wsClient) {
129+
wsClient = withAbsintheSocket.create(_ws);
130+
return wsClient;
134131
}
135132

136-
return null;
133+
return wsClient;
137134
}
138135

139136
const evaluatedQueries = {

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,10 @@ export const listenToSandboxChanges: AsyncAction<{
10601060
}> = async ({ state, actions, effects }, { sandboxId }) => {
10611061
effects.gql.subscriptions.onSandboxChangged.dispose();
10621062

1063+
if (!state.isLoggedIn) {
1064+
return;
1065+
}
1066+
10631067
effects.gql.subscriptions.onSandboxChangged({ sandboxId }, result => {
10641068
const sandbox = state.editor.sandboxes[sandboxId];
10651069

@@ -1084,7 +1088,7 @@ export const loadCollaborators: AsyncAction<{ sandboxId: string }> = async (
10841088
{ state, effects },
10851089
{ sandboxId }
10861090
) => {
1087-
if (!state.editor.currentSandbox) {
1091+
if (!state.editor.currentSandbox || !state.isLoggedIn) {
10881092
return;
10891093
}
10901094

packages/app/src/app/overmind/onInitialize.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export const onInitialize: OnInitialize = async (
3333
Authorization: `Bearer ${state.jwt}`,
3434
}),
3535
},
36-
effects.live.getSocket()
36+
// TODO(@christianalfoni): we need to make this dynamic, but overmind devtools can't serialize a socket with one channel.
37+
// Because of this the app crashes if we want to provide it with a function
38+
effects.jwt.get() ? effects.live.getSocket() : null
3739
);
3840

3941
effects.notifications.initialize({

0 commit comments

Comments
 (0)