pocketbase 的文档对于如何在使用 pb_hooks 时检查经过身份验证的用户而言并不清晰
事实证明真的简单
https://pocketbase.io/docs/js-routing/#sending-request-to-custom-routes-using-the-sdks
https://pocketbase.io/jsvm/functions/_apis.requireAdminOrRecordAuth.html
// main.pb.js // This is a simple GET route, that is protected routerAdd("GET", "/private", (c) => { const data = { message : "This can only be accessed if you are logged in" } return c.json(200, data) // Adding the $apis.requireAdminOrRecordAuth() argument, ensures the route is protected unless the user is logged in. }, $apis.requireAdminOrRecordAuth()); // This is a simple GET route, that is public routerAdd("GET", "/public", (c) => { const data = { message : "This can be be accessed by public" } return c.json(200, data) });
然后只需使用 pocketbase 调用路线即可
// let fetchData = async () => { let resp = await pocketBaseClient.pb.send("/private", { }); console.log(resp) }
以上是Pocketbase pb_hooks - 检查用户身份验证的详细内容。更多信息请关注PHP中文网其他相关文章!