
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
例子 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | routerAdd( "GET" , "/private" , (c) => {
const data = {
message : "This can only be accessed if you are logged in"
}
return c.json(200, data)
}, $apis .requireAdminOrRecordAuth());
routerAdd( "GET" , "/public" , (c) => {
const data = {
message : "This can be be accessed by public"
}
return c.json(200, data)
});
|
登录后复制
然后只需使用 pocketbase 调用路线即可
1 2 3 4 5 6 | let fetchData = async () => {
let resp = await pocketBaseClient.pb.send( "/private" , {
});
console.log(resp)
}
|
登录后复制
以上是Pocketbase pb_hooks - 检查用户身份验证的详细内容。更多信息请关注PHP中文网其他相关文章!