+13
-27
src/lib/states/session.tsx
+13
-27
src/lib/states/session.tsx
···
22
23
import { type Labeler, attachLabelerHeaders } from '../atproto/labeler';
24
import { makeAbortable } from '../hooks/abortable';
25
-
import { createReactiveLocalStorage, isExternalWriting } from '../hooks/local-storage';
26
import type { PerAccountPreferenceSchema } from '../preferences/account';
27
import type { AccountData } from '../preferences/sessions';
28
import { assert } from '../utils/invariant';
···
144
return;
145
}
146
147
const signal = getSignal();
148
149
const session = await oauthSessions.get(did, { allowStale: true });
···
195
}
196
},
197
};
198
-
199
-
createEffect(() => {
200
-
const active = sessions.active;
201
-
202
-
// Only run this on external changes
203
-
if (isExternalWriting) {
204
-
const untrackedState = untrack(state);
205
-
206
-
if (active) {
207
-
if (active !== untrackedState?.did) {
208
-
// Current active account doesn't match what we have
209
-
210
-
// Still logged in, so log out of this one
211
-
if (untrackedState) {
212
-
replaceState(undefined);
213
-
}
214
-
215
-
// Try to resume from this new account if we have it.
216
-
context.resumeSession(active);
217
-
}
218
-
} else if (untrackedState) {
219
-
// No active account yet we have a session, log out
220
-
replaceState(undefined);
221
-
}
222
-
}
223
-
});
224
225
return <Context.Provider value={context}>{props.children}</Context.Provider>;
226
};
···
22
23
import { type Labeler, attachLabelerHeaders } from '../atproto/labeler';
24
import { makeAbortable } from '../hooks/abortable';
25
+
import { createReactiveLocalStorage } from '../hooks/local-storage';
26
import type { PerAccountPreferenceSchema } from '../preferences/account';
27
import type { AccountData } from '../preferences/sessions';
28
import { assert } from '../utils/invariant';
···
144
return;
145
}
146
147
+
// If we already have a session, reload...
148
+
if (state()) {
149
+
batch(() => {
150
+
sessions.active = did;
151
+
sessions.accounts = [account, ...sessions.accounts.filter((acc) => acc.did !== did)];
152
+
153
+
location.reload();
154
+
});
155
+
156
+
return;
157
+
}
158
+
159
const signal = getSignal();
160
161
const session = await oauthSessions.get(did, { allowStale: true });
···
207
}
208
},
209
};
210
211
return <Context.Provider value={context}>{props.children}</Context.Provider>;
212
};