Home>

I am trying monaca backend API (login) on monaca.
I'm not using it well, so I want to know how to use it.

The problem you ’re experiencing

The backend API (monaca.cloud.User.login ()) does not work as expected.
User name and password are used for monaca backend user management when calling the following javascript
It is assumed that login will be successful if registered, and login failure alerts if not.
However, no alert is displayed and nothing happens.

I want to display an alert and check the operation of the backend API.

Applicable source code
monaca.cloud.User.login ("user name", "password")
    .done (function (result) {
       ons.notification.alert ({message: "Login successful"});
    })
    .fail (function (err)
    {
       ons.notification.alert ({message: "Login failure"});
    });
Things and situations

・ Confirm that javascript is called
→ The ons.notification.alert output just before the above source code was confirmed

・ Linking project and backend
→ https: //docs.monaca.io/en/tutorials/monaca_ide/adding_backend/
Perform step 1 above. I haven't created a collection

-Add users in backend user management
→ No columns added from the initial state. Enter the username and password of the added user
Set as backend API argument

-I tried other APIs, but nothing worked.

Environment

Cordova plugin
It has not changed from the creation of the sample project using the js framework.
monaca backend: v2.1.0 is valid

・ js/css component
Cordova (PhoneGap) Loader: 1.0.0
jQuery: 3.4.1
Monaca Core Utility: 2.0.7
monaca-jquery: 3.3.1
Onsen UI (Monaca Version): 2.10.10

・ Check with monaca IDE debugger

  • Answer # 1

    As far as I looked at it, it seems that this is because it doesn't contain APIKEY.

    I personally think that MonacaIDE doesn't assume a connection (I don't use MonacaIDE even in the tutorial), but if you do it forcibly

    ons.ready (function () {
          console.log ("Onsen UI is ready!");
          // url, backendId, and apiKey are in config.xml in MonacaIDE
          monaca.cloud.url = '';// monaca: MonacaBackendUrl value
          monaca.cloud.backendId = '';// monaca: MonacaBackendId value
          monaca.cloud.apiKey = '';// monaca: MonacaBackendApiKey value
          monaca.cloud.deviceId = 'hoge';//<-This is appropriate
          monaca.cloud.User.login ("test", "test")
          .done (function (result) {
            console.log ('done');
            console.log (result);
            ons.notification.alert ({message: "Login successful"});
          })
          .fail (function (err) {
            console.log ('fail');
            console.log (err);
            ons.notification.alert ({message: "Login failure"});
          });
        });


    It seems to work for the time being (I get an error in a different place but ignore it for now)

    * It may be better to use NiftyCloud.