Stackedit/src/services/userSvc.js

29 lines
668 B
JavaScript
Raw Normal View History

2017-11-15 08:12:56 +00:00
import googleHelper from '../services/providers/helpers/googleHelper';
import store from '../store';
const promised = {};
export default {
getInfo(userId) {
if (!promised[userId]) {
// Try to find a token with this sub
const token = store.getters['data/googleTokens'][userId];
if (token) {
store.commit('userInfo/addItem', {
id: userId,
name: token.name,
});
}
// Get user info from Google
if (!store.state.offline) {
promised[userId] = true;
googleHelper.getUser(userId)
.catch(() => {
promised[userId] = false;
});
}
}
},
};