async currentUser()

in src/ui/graphql/apollo_client/resolvers.js [38:71]


    async currentUser(_, __, { cache }) {
      const {
        accessToken,
        gitlabInstance: { host },
      } = getUserConfigFromCache(cache);
      if (!accessToken) throw new Error('Access token is not set.');
      if (!host) throw new Error('GitLab instance host is not set.');

      return fetch(restApiUri(host, '/user'), {
        headers: {
          Authorization: `Bearer ${accessToken}`,
        },
      })
        .then(res => {
          if (res.status !== 200) {
            return res.json().then(({ message }) => {
              throw new Error(message);
            });
          }

          return res;
        })
        .then(res => res.json())
        .then(data => {
          const { id, name, username } = data;

          return {
            __typename: 'User',
            id,
            name,
            username,
          };
        });
    },