/// // Keeps superusers off the public port. nginx marks every request that // arrives on port 8000 with an X-Public-Port header; there, superusers get // nowhere: no sign-in, no password reset, no one-time codes, no superuser // tokens. They work on port 8090, which exe.dev keeps behind its login. // // Saved as ~/pocketbase/pb_hooks/private-superusers.pb.js. From // https://exe.dev/deploy/pocketbase routerUse((e) => { if (!e.requestInfo().headers["x_public_port"]) { return e.next() // port 8090 } // Routes like /api/collections/{collection}/auth-with-password take a // name or an id, in any letter case: look the collection up. let collection = null const name = e.request.pathValue("collection") if (name) { try { collection = e.app.findCachedCollectionByNameOrId(name) } catch (_) {} } if (e.hasSuperuserAuth() || (collection && collection.name === "_superusers")) { throw new ForbiddenError("Superusers use the private port.") } return e.next() })