How to use Mongodb Realm with Cordova?

From the Asset Store
2D isometric medieval style building and object sprites.
  • Hey there!

    With the help of DiegoM I was able to install Mongodb's Web SDK into my project.

    But now a new problem has arisen. My plan is to build a mobile app, exporting to Cordova. But then obviously redirection from the Realms Web SDK built in OAuth2 Facebook Login will not work anymore. Also I'm not sure if the built in functions of the Web SDK will work inside Cordova. They might though, as Cordova is just a browser app, if I'm not wrong.

    My problem now is to let the user sign in to Mongodb Realm using the SDKs built in Facebook OAuth2 without redirection.

    (The next problem will be using API calls or the built in SDK to retreive and post Database information as the Realm documentation, although pretty detailed, lacks very much of detailed code examples. There are just confusing variations of incomplete code snippets for the same thing scattered across multiple sites. But that will be the next step and maybe part of a future question when I get the sign in with Cordova working. :D)

    Any ideas?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hello past me.

    I don't know how but I got an enlightenment and figured it out by myself.

    You just need the Facebook access token which you get using Construct 3's built in FB plugin + you need Web Facebook or something similar to get the access token (Why don't we have this important feature built in?)

    Just set the global variable access_token to WebFacebook.GetAccessToken inside the facebook on logged in condition.

    Then add script and paste the following code (You must have the Realm Web SDK loaded):

    const id = "your-realm-app-id";
    const config = {
     id,
    };
    const app = new Realm.App(config);
    
    
    const credentials = Realm.Credentials.facebook(runtime.globalVars.access_token);
    
    app.logIn(credentials).then(user => {
     
     console.log(`[Realm] Logged in with id: ${user.id}`);
     
    })

    It must look like this:

    And this:

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)