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中文網其他相關文章!