如何使用自定义身份验证启动Realm Object服务器



我已经更新了基于自定义身份验证的index.js文件https://realm.io/docs/realm-object-server/latest/index.html#custom-authentication

以下是我的index.js文件的内容

const RealmObjectServer = require('realm-object-server');
const path = require('path');
const Realm = require('realm');
const server = new RealmObjectServer.BasicServer();
// Update the default path where Realm will be stored.
Realm.defaultPath = './data/realms/MyCustomRealm.realm'
class MyAuthProvider extends RealmObjectServer.auth.AuthProvider {
    constructor() {
        super();
        this.name = 'myAuthProvider';
        console.log("Realm default Path = " + Realm.defaultPath)
    }
    authenticateOrCreateUser(body) {
        console.log("In authenticateOrCreateUser with body = ", body)
        const userId = body.userId;
        return this.service.createOrUpdateUser(
                                               userId,
                                               "myAuthProvider",
                                               false,
                                               null
                                               );
    }
}
server.start({
             dataPath: path.join(__dirname, '../data'),
             authProviders: [ new MyAuthProvider() ],
             }).catch((err) => {
                      console.error("There was an error starting your custom ROS Server", err);
                      });

如何启动服务器,以便称为" AuthenticateOrcreateuser"方法?

我尝试进行以下操作:

ros start --auth myAuthProvider
ros start --auth MyAuthProvider

但有以下错误:

The auth provider 'myAuthProvider' cannot be found or does not have a default export
The auth provider 'MyAuthProvider' cannot be found or does not have a default export

我是JavaScript的新手

任何帮助将不胜感激。谢谢!

尝试使用

启动服务器

npm开始

来自您的应用程序目录。

相关内容

  • 没有找到相关文章

最新更新