kleros/kleros-v2

View on GitHub
kleros-app/src/lib/atlas/utils/fetchUser.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { gql, type GraphQLClient } from "graphql-request";

export type User = {
  email: string;
  isEmailVerified: string;
  emailUpdateableAt: string | null;
};

type GetUserResponse = {
  user: User;
};
const query = gql`
  query GetUser {
    user {
      email
      isEmailVerified
      emailUpdateableAt
    }
  }
`;

export async function fetchUser(client: GraphQLClient): Promise<User> {
  return client
    .request<GetUserResponse>(query)
    .then((response) => response.user)
    .catch((errors) => {
      // eslint-disable-next-line no-console
      console.log("Error fetching user :", { errors });
      const errorMessage = Array.isArray(errors?.response?.errors)
        ? errors.response.errors[0]?.message
        : "Error fetching user";
      throw Error(errorMessage);
    });
}