import { ConvexError } from "convex/values";

export interface AuthContext {
  readonly auth: {
    readonly getUserIdentity: () => Promise<{
      readonly tokenIdentifier: string;
    } | null>;
  };
}

export const requireOwnerId = async (ctx: AuthContext): Promise<string> => {
  const identity = await ctx.auth.getUserIdentity();
  if (!identity) {
    throw new ConvexError("Authentication required");
  }
  return identity.tokenIdentifier;
};
