Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

843 B
Raw Blame
import type { Context, Next } from "hono";
import { ApiError } from "../errors/api-error";
import getManagedProfile from "./controllers/get-managed-profile";
import {
  canRemoveAvatar,
  PROFILE_FIELD_MANAGED_BY_PROVIDER,
} from "./managed-profile";

export async function requireUnmanagedAvatar(c: Context, next: Next) {
  const managed = await getManagedProfile(c.get("userId"));
  if (managed?.fields.includes("image")) {
    throw new ApiError(403, { ...PROFILE_FIELD_MANAGED_BY_PROVIDER });
  }
  return next();
}

export async function requireRemovableAvatar(c: Context, next: Next) {
  const managed = await getManagedProfile(c.get("userId"));
  if (
    managed?.fields.includes("image") &&
    !canRemoveAvatar(managed.stored.image)
  ) {
    throw new ApiError(403, { ...PROFILE_FIELD_MANAGED_BY_PROVIDER });
  }
  return next();
}