Skip to content

Commit

Permalink
Looking to reduce calls to the api for unauthenticated users
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Tucker committed May 18, 2021
1 parent d4fc89c commit 868f386
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ export default {
path: 'selfInvitations/get',
});
return data.map((invite) => new GroupInvitationViewModel(invite));
if(data.map){
return data.map((invite) => new GroupInvitationViewModel(invite));
} else {
return {}
}
},
async acceptInvitation(currentInvitation) {
return await this.accessGroupApi.execute({
Expand Down
30 changes: 21 additions & 9 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import user from './user.store';
import scope from './scope.store';
import features from './features.store';

let shouldFetch = true;

async function fetchUser(commit) {
if (shouldFetch === false){
return
}
try {
const fetchPolicy = 'network-only';
const { data } = await client.query({
Expand All @@ -19,14 +24,21 @@ async function fetchUser(commit) {
commit('setUser', data.profile);
return true;
} catch (e) {
const {
graphQLErrors: [{ message }],
} = e;
if (message === 'wait_for_profile') {
console.log('creating');
}
commit('setUser', { loggedIn: true });
return false;
try {
const {
graphQLErrors: [{ message }],
} = e;
if (message === 'wait_for_profile') {
console.log('creating');
}
commit('setUser', { loggedIn: true });
return false;
}
catch(e) {
// Probably getting a 403 for authentication
shouldFetch = false
return false
}
}
}

Expand Down Expand Up @@ -101,4 +113,4 @@ export async function resolvePromisesSerially(promises, resolvers) {
console.error(e.message);
throw new Error(e.message);
}
}
}

0 comments on commit 868f386

Please sign in to comment.