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