Skip to Content

How to clear the cookie in mobile application when click on logout button?


I have done one mobile application using SAPUI5 and Gateway service. In that application I have login page. First time when I send the request with wrong credentials  it goes to error function and displaying some error message. second time when I enter valid credentials it goes to success function and connected with back end and I can get the records.

But my problem is third time when I again enter into the application with wrong credentials, it doesn't goes to the error function.It directly goes to the success function and I am getting data from back end.

I used the below code to send the username and password to the back end.

logindialog.setRightButton(new sap.m.Button({

                              text: "Ok",

                              type: "Accept",

                        tap: function(oEvent) {

                                  username = usernameinput.getValue();

                                  password = pwdinput.getValue();

                                  encrypted = btoa(''+username+':'+password+'');


requestUri : "$format=json",

headers : {

   Authorization : "Basic "+ encrypted


}, function(data) {



var myapp = sap.ui.jsview("view.App");



}, function(err) {


window.alert("Authentication Failed");





I am guessing that the username and password values are stored in cookies.

How can I find those fields and remove those values from cookies in mobile when click on logout button?

Please help me to solve this issue.



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Oct 11, 2013 at 02:19 PM

    Try setting your cookie like this to invalidate it:

                          document.cookie = 'YOURCOOKIE=; max-age=0; expires=Thu, 01 Jan 1970 00:00:01 GMT;';

    You cannot un-set it if it's a HttpOnly cookie. And you may need to add a path or domain.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 11, 2013 at 09:38 PM

    Hi Sridevi,

    Check out jquery.cookie. It's simple, lightweight jQuery plugin for reading, writing and deleting cookies. There are no problems to combine this plugin with SAPUI5. For deleting a Cookie you can just write the following code in your click-handler:

    // Returns true when cookie was found, false when no cookie was found...


    Regards Michael

    Add comment
    10|10000 characters needed characters exceeded