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) }
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3