I have updated index.js file with custom authentication based on https://realm.io/docs/realm-object-server/latest/index.html#custom-authentication
Below is the content of my index.js file
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);
});
How do I start the server so that my "authenticateOrCreateUser" method is called?
I tried doing following:
ros start --auth myAuthProvider
ros start --auth MyAuthProvider
but got following errors:
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
I am new to javascript so not sure what default export is and how can it be added?
Any help is appreciated. Thanks!