8 Replies Latest reply on Jun 4, 2014 6:22 AM by Mark Ross

    RhoConnect custom route without authentication

    Mark Ross

      My RhoConnect client is written in javascript.  I would like to add a custom route which does not require authentication (logged into RhoConnect).  I know this is possible in Ruby by specifying:


      get '/my_custom_route', :login_required => false


      Is the same available when writing the method in javascript?  Here's my code:


      app.post('/my_custom_route', {}, function(req, resp){
        // should get here without being logged into RhoConnect
        console.log('req', req);


      When I try the above code in RhoConnect, I get this http response:


      body: "Not authenticated"

      error_code: "9"

      headers: Object

      http_error: "401"

      status: "error"




        • Re: RhoConnect custom route without authentication

          Your custom route in JS doesn't specify :login_required => false. Please use this:


          1. app.post('/my_custom_route', {'login_required':false}, function(req, resp){ 
          2.   // should get here without being logged into RhoConnect 
          3.   console.log('req', req); 
          4. }); 


          • Re: RhoConnect custom route without authentication



            You will need to add a couple more arguments in order to make this work. I just double checked the following code, and it works.


            app.post('/my_custom_route2', {'login_required':false, "source_required":false, "client_required":false}, function (req, resp){



            1 of 1 people found this helpful
              • Re: Re: RhoConnect custom route without authentication
                Mark Ross



                For some reason, its still not working for me.  I've added the parameters you mentioned and I still get the "Not authenticated" error from Rhoconnect.  Here's my exact code in case I'm missing something.


                Mobile client:

                  url: 'http://localhost:9292/app/v1/regActionLogin',
                  body: {
                  data: "test"
                }, function(e) {
                  if (e.http_error == "200") {
                       var user = JSON.parse(e.body);
                       console.log('regAction response', user);
                       self.router.navigate('login', {trigger: true});
                  } else {
                       console.log('e', e);
                            title: 'Bad Login',
                            message: 'Your username/password were incorrect. Please try again.', 
                            icon: ":alert",
                            buttons: [{id: 'yes', title: 'OK'}]
                       }, function() {


                Rhoconnect application_controller.js:

                app.post('/regActionLogin', {'login_required':false, "source_required":false, "client_required":false}, function(req, resp){
                  console.log('req', req);


                Log from Rhoconnect:

       - - [02/Jun/2014 09:32:26] "POST /app/v1/regActionLogin HTTP/1.1" 401 17 0.0260


                Response in mobile app:

                e Object {body: "Not authenticated", error_code: "9", http_error: "401", status: "error", headers: Object}



                I'm using Rho 4.1.0 and Rhoconnect 4.1.0 on Windows 7 testing with the Rhosimulator.

                  • Re: RhoConnect custom route without authentication

                    You're defining your route in application controller, which has prefix "rc/v1/app". So, your route in client call should be:


                    1. Rho.Network.post({ 
                    2.   url: 'http://localhost:9292/rc/v1/app/regActionLogin'
                    3.   body: { 
                    4.   data: "test" 
                    5.   } 
                    6. }

                    Also, I wouldn't recommend using "localhost" at all even in simulator. I would advise using exact IP address instead. Some simulators (for example, Android) use separate virtual machine and localhost on Android simulator would not be the same as on your Windows desktop.

                    FYI: There is a 'rhoconnect routes' command which will show you all of the routes defined in your RhoConnect application. You can use it for debugging. Just execute this command from the root of your RC app.