// jsonwebtoken -> jws -> jwa -> buffer-equal-constant-time (last published ~2017,
// never updated) reads `SlowBuffer.prototype` at module-load time purely to
// support an opt-in Buffer.prototype.equal monkey-patch that this codebase
// never calls. Node fully removed `buffer.SlowBuffer` (it was deprecated for
// years before that), so requiring jsonwebtoken crashes on newer Node with
// "Cannot read properties of undefined (reading 'prototype')" before the app
// even boots. This restores a harmless stand-in so that module can load.
// Real fix: run the server on an LTS Node version instead of relying on this.
import { Buffer } from "buffer";

const bufferModule = require("buffer");
if (!bufferModule.SlowBuffer) {
  function SlowBuffer(length: number) {
    return Buffer.alloc(length);
  }
  SlowBuffer.prototype = Buffer.prototype;
  bufferModule.SlowBuffer = SlowBuffer;
}
