Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 1x 1x 1x 26x 26x 26x 26x 26x 26x 26x | import type { FastifyPluginAsync } from "fastify";
import type { AppConfig } from "../config.js";
import { requireVerifiedUser, type IdTokenVerifier } from "../lib/firebase-auth.js";
import { proxyJsonRequest } from "../lib/http-client.js";
/** Опасная зона: удаление данных / аккаунта. uid берётся из ID-токена. */
export const accountRoutes: FastifyPluginAsync<{
config: AppConfig;
verifyIdToken: IdTokenVerifier;
}> = async (app, opts) => {
const { config, verifyIdToken } = opts;
function userHeaders(uid: string): Record<string, string> {
return { "x-service-token": config.serviceToken, "x-user-uid": uid };
}
app.delete("/account/data", async (request) => {
const user = await requireVerifiedUser(request, verifyIdToken);
return proxyJsonRequest<unknown>({
method: "DELETE",
url: `${config.catalogServiceUrl}/account/data`,
headers: userHeaders(user.uid),
body: {},
timeoutMs: config.upstreamTimeoutMs,
});
});
app.delete("/account", async (request) => {
const user = await requireVerifiedUser(request, verifyIdToken);
return proxyJsonRequest<unknown>({
method: "DELETE",
url: `${config.catalogServiceUrl}/account`,
headers: userHeaders(user.uid),
body: {},
timeoutMs: config.upstreamTimeoutMs,
});
});
};
|