This commit is contained in:
j3d1 2026-08-24 12:36:17 +02:00
parent 8f3236b5b4
commit 8d96bc97c4
3 changed files with 62 additions and 11 deletions

View file

@ -75,6 +75,7 @@ export default createStore({
groups: [],
groupInvites: [],
idmap: {identities: [], groups: []},
idmapLoaded: false,
item_map: {},
home_servers: null,
all_friends_servers: null,
@ -115,6 +116,7 @@ export default createStore({
},
setIdMap(state, idmap) {
state.idmap = idmap;
state.idmapLoaded = true;
},
setHomeServers(state, home_servers) {
state.home_servers = home_servers;
@ -334,9 +336,18 @@ export default createStore({
// signature check on the receiving end fail against the real request.
(answer) => answer.port === 443 ? answer.target : answer.target + ':' + answer.port))
},
async getHomeServers({state, dispatch, commit}) {
async getHomeServers({state, dispatch, commit, getters}) {
if (state.home_servers)
return state.home_servers
// isLoggedIn (store.js's getters) is what lazily hydrates state.user/token/keypair
// from localStorage on first read - a route with no requiresAuth meta (e.g. the
// short-id redirect) never triggers that beforeEach check, so state.user can still be
// null here even for an actually-logged-in visitor. Reading the getter first forces
// that hydration; if it's still false afterwards, the visitor really isn't logged in,
// so fail with a clear error instead of lookupServer crashing on username.split(...).
if (!getters.isLoggedIn) {
throw new Error('Not logged in')
}
const promise = dispatch('lookupServer', {username: state.user}).then(servers => new ServerSet(servers, state.unreachable_neighbors))
commit('setHomeServers', promise)
return promise