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.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github charliewilco / downwrite / utils / resolvers.ts View on Github external
export const verifyCredentials = async (
  { password, username: identifier }: Omit,
  userGetter: (id: string) => Promise
) => {
  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,
  userGetter: (id: string) => Promise
) => {
  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;
  };