UNPKG

firebase-tools

Version:
44 lines (43 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.set_claim = void 0; const zod_1 = require("zod"); const tool_js_1 = require("../../tool.js"); const util_js_1 = require("../../util.js"); const auth_js_1 = require("../../../gcp/auth.js"); exports.set_claim = (0, tool_js_1.tool)({ name: "set_claim", description: "Sets a custom claim on a specific user's account. Use to create trusted values associated with a user e.g. marking them as an admin. Claims are limited in size and should be succinct in name and value. Specify ONLY ONE OF `value` or `json_value` parameters.", inputSchema: zod_1.z.object({ uid: zod_1.z.string().describe("the UID of the user to update"), claim: zod_1.z.string().describe("the name (key) of the claim to update, e.g. 'admin'"), value: zod_1.z .union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()]) .optional() .describe("Set the value of the custom claim to the specified simple scalar value. One of `value` or `json_value` must be provided."), json_value: zod_1.z .string() .optional() .describe("Set the claim to a complex JSON value like an object or an array by providing stringified JSON. String must be parseable as valid JSON. One of `value` or `json_value` must be provided."), }), annotations: { title: "Set custom Firebase Auth claim", idempotentHint: true, }, _meta: { requiresAuth: true, requiresProject: true, }, }, async ({ uid, claim, value, json_value }, { projectId }) => { if (value && json_value) return (0, util_js_1.mcpError)("Must supply only `value` or `json_value`, not both."); if (json_value) { try { value = JSON.parse(json_value); } catch (e) { return (0, util_js_1.mcpError)(`Provided \`json_value\` was not valid JSON: ${json_value}`); } } return (0, util_js_1.toContent)(await (0, auth_js_1.setCustomClaim)(projectId, uid, { [claim]: value }, { merge: true })); });