How to use the apollo-server-micro.AuthenticationError function in apollo-server-micro

To help you get started, we’ve selected a few apollo-server-micro examples, based on popular ways it is used in public projects.

github charliewilco / downwrite / utils / resolvers.ts View on Github external
export const verifyCredentials = async (
  { password, username: identifier }: Omit<IMutationUserVars, "email">,
  userGetter: (id: string) => Promise<IUser>
) => {
  const user: IUser = await userGetter(identifier);

  if (user) {
    const isValid = await bcrypt.compare(password, user.password);
    if (isValid) {
      return user;
    }
    throw new AuthenticationError("Incorrect password!");
  } else {
    throw new AuthenticationError("Incorrect username or email!");
  }
};
github charliewilco / downwrite / utils / resolvers.ts View on Github external
export const verifyCredentials = async (
  { password, username: identifier }: Omit<IMutationUserVars, "email">,
  userGetter: (id: string) => Promise<IUser>
) => {
  const user: IUser = await userGetter(identifier);

  if (user) {
    const isValid = await bcrypt.compare(password, user.password);
    if (isValid) {
      return user;
    }
    throw new AuthenticationError("Incorrect password!");
  } else {
    throw new AuthenticationError("Incorrect username or email!");
  }
};
github este / este / packages / api / models / createPermissions.ts View on Github external
const isAuthenticated = (userId?: string): NexusGenAllTypes['User'] => {
    if (user == null || (userId != null && user.id !== userId))
      throw new AuthenticationError('you must be logged in');
    return user;
  };