Page 2 of 3

How to keep users logged in, until they logout.

Posted: Mon May 11, 2015 7:02 am
by rajanmr

I have shared the app with the support, here are the details you asked for

1)app name : test3
2)credentials : Please register a new acc, so that you can know the problem
3) Detailed steps to reproduce the issue
Just register a new account, and then request the first service inside, then close the app and re-open the app, it will ask for login again

Thanks


How to keep users logged in, until they logout.

Posted: Tue May 12, 2015 5:28 am
by rajanmr

Hi Stepanov!

Can you please confirm, that you have got access to the app?


How to keep users logged in, until they logout.

Posted: Tue May 12, 2015 8:28 pm
by Illya Stepanov

Hi Rajan -

Yes, we have access to your app. We need some time to test it on a device.


How to keep users logged in, until they logout.

Posted: Wed May 13, 2015 6:09 am
by rajanmr

ok thanks, will await your reply.


How to keep users logged in, until they logout.

Posted: Fri May 15, 2015 5:09 am
by rajanmr

Hi!

i am still waiting for your reply.


How to keep users logged in, until they logout.

Posted: Fri May 15, 2015 7:42 am
by Alena Prykhodko

Sorry for delay. Working on it.
We'll reply as soon as have news.


How to keep users logged in, until they logout.

Posted: Wed May 20, 2015 12:38 am
by Yurii Orishchuk

Hi rajanmr,

The problem you have is not in login. After app restarts - it will load start screen. Your start screen is login thus you have this form.

Your local storage variable stored after restart the app and you need to check it and pass login page(navigate to needed page).

Regards.


How to keep users logged in, until they logout.

Posted: Wed May 20, 2015 2:42 am
by rajanmr

Thanks Yuri!

Can you throw some light into how and what to check with the local storage variable. Should i have a blank page as start screen and check whether sessionid is available in local storage? Please clarify what to check.


How to keep users logged in, until they logout.

Posted: Wed May 20, 2015 4:28 am
by Yurii Orishchuk

Ramanmr,

Yes here is a solution to check if session token stored, verify this token and then make logic what to open.

  1. At first add to your app "getUser"(call it the same) service.
    Solution how to do will be posted below.

  2. Create new page and call it "verifyUser". You can populate this page with content you need to show/or not show about current process.

  3. Make this page as start page of your app.

  4. Add to this page on "Data" tab "getUser" service datasource and call it "getUserDatasource".
    Details: http://prntscr.com/778aa7/direct

  5. Open "Before send" mapping for "getUserDatasource". And link from storage(where you store your sessionToken) to "X-Appery-Sessoin-token" request parameter. And inside "userId" request parameter put "111".
    Details: http://prntscr.com/778bwz/direct

  6. Add "Complete" event handler with action "Run javascript". And use following JS code for this handler:
    Details: http://prntscr.com/778e1h/direct

    precode

    var responseText = jqXHR.responseText;

    var responseObject = JSON.parse(responseText);

    var isSessionCorrect = false;

    if(responseObject.code == "DBUG210")
    isSessionCorrect = true;

    console.log("isSessionCorrect = " + isSessionCorrect);

    if(isSessionCorrect){
    //Navigate to page you need if session token is correct.
    Apperyio.navigateTo("test");
    }
    else{
    //Navigate to login page if session token is NOT correct.
    Apperyio.navigateTo("login");
    };

    /code/pre

    Note: you need to change "test" and "login" page with your destination pages.

  7. Invoke this service datasource on the "page show event handler.
    Details: http://prntscr.com/778eah/direct

    That's all.

    Regards.


How to keep users logged in, until they logout.

Posted: Wed May 20, 2015 4:31 am
by Yurii Orishchuk

And here is a solution about how to add "getUser" service in your app:

  1. Create REST service and call it "getUser".
    Details: http://prntscr.com/5vurg1/direct

  2. On "Settings tab" use following settings:
    Details: http://prntscr.com/5vusim/direct

    URL: "https://api.appery.io/rest/1/db/users..."
    Method: "GET"
    Response Data Type: "JSON"
    Settings: your DB settings service.

  3. Request tab(headers):
    Details: http://prntscr.com/5vutfn/direct

    Add following parameters:
    "X-Appery-Database-Id" = "{database_id}"
    "X-Appery-Session-Token" = ""

  4. Request tab(queryString):
    Details: http://prntscr.com/5vut9y/direct

    Add following parameters:
    "userId" = ""

  5. In "response" tab you need to set your user details parameters. Like on the screen shots: http://prntscr.com/5vutoh/direct

    Regards.