none
Lifetime of the app object in OfficeJS RRS feed

  • Question

  • I'm developing an Excel Pane App using OfficeJS 1.1 to Access data from Our OData API. The API requires login credentials, so I've created a login page.

    Now I need to store the user token for reuse in all following API Calls. My first though was to store it in a property in the app Object (from App.js) in Login.js, but that seems to be recreated after the redirect back to the main page, so the token property is undefined when I try to Access it in Home.js.

    Am I doing something wrong, or is this by design? If this is by design, what would be the most appropriate way to store a user token in an Excel Pane App?


    eloekset

    Tuesday, July 15, 2014 2:29 PM

Answers

  • Hi Eloekset,

    You could use JQuery/JavaScript to make cookie to store data in this Excel task pane app.

    If you search "JQuery Cookie", you will find many resource.

    Here are some code for your reference:

    Create session cookie:

    $.cookie('name', 'value');


    Create expiring cookie, 7 days from then:

    $.cookie('name', 'value', { expires: 7 });


    Create expiring cookie, valid across entire site:

    $.cookie('name', 'value', { expires: 7, path: '/' });


    Read cookie:

    $.cookie('name'); // => "value"
    $.cookie('nothing'); // => undefined


    Read all available cookies:

    $.cookie(); // => { "name": "value" }


    Delete cookie:

    // Returns true when cookie was successfully deleted, otherwise false
    $.removeCookie('name'); // => true
    $.removeCookie('nothing'); // => false

    // Need to use the same attributes (path, domain) as what the cookie was written with
    $.cookie('name', 'value', { path: '/' });
    // This won't work!
    $.removeCookie('name'); // => false
    // This will work!
    $.removeCookie('name', { path: '/' }); // => true

    Hope this helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 16, 2014 5:58 AM
    Moderator