无需登录用户调用云代码 Parse Server JS SDK

Call cloud code without logged in user Parse Server JS SDK

是否可以在没有当前用户的情况下调用 returns 对象的云函数? iOS 和 Android SDK 支持匿名用户,但我特别要求 JavaScript。

我想允许任何访问我的网络应用程序的人无需登录即可读取对象。我正在使用 Back4App。

是的。无论用户是否登录,您都可以调用云代码功能。在云函数中,您可以检查 request 对象的 user 属性 以检查用户是否已登录。如果你的用户没有登录,你想查询一个需要用户权限的class,你可以使用useMasterKey选项。

Parse.Cloud.define('myFunction', async req => {
  const { user, isMaster } = req;

  if (isMater) {
    // the cloud code function was called using master key
  } else if (user) {
    // the cloud code function was called by an authenticated user
  } else {
    // the cloud code function was called without passing master key nor session token - not authenticated user
  }

  const obj = new Parse.Object('MyClass');
  await obj.save(null, { useMasterKey: true }); // No matter if the user is authenticated or not, it bypasses all required permissions - you need to know what you are doing since anyone can fire this function

  const query = new Parse.Query('MyClass');
  return query.find({ useMasterKey: true }) // No matter if the user is authenticated or not, it bypasses all required permissions - you need to know what you are doing since anyone can fire this function
});