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

时间:2017-11-21 16:34:57

标签: javascript realm realm-object-server

我已经使用自定义身份验证更新了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的新手,所以不确定默认导出是什么以及如何添加?

感谢任何帮助。 谢谢!

1 个答案:

答案 0 :(得分:0)

尝试使用

启动服务器

npm start

来自你的app目录。