# Javascript sdk - Authentification login required on each page

**URL:** <https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071>\
**Category:** Authentication & Security\
**Created:** [May 5, 2015, 8:50am UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071 "2015-05-05T08:50:17Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [May 5, 2015, 8:50am UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/1 "2015-05-05T08:50:17Z")

</div>

Hi there  
i’m trying to build an web app based on dreamfactory and javascript sdk  
based on Jquery app  
i’m trying to integrate jquery app in a boostrap template devoops-master fond on dreamfactory github repository  
so i’ve create many html file with jquery app  
i call this page with the navigation menu on the left.  
my problem is that on each page ths sdk ask my for login even if i’m already login (when file are on my server ubuntu 14)  
i don’t have this issu when running localy (on imac) .  
is there any way to check for session instead of asking for a login ?  
any example would be more than welcome 😄

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [May 5, 2015, 5:54pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/2 "2015-05-05T17:54:35Z")

</div>

If you’re getting prompted to login on every single action, you are likely not passing the `session_id` to the DSP. Your session should persist for as long as you’ve set the `duration` parameter at login. Check out [this page from the documentation](https://github.com/dreamfactorysoftware/dsp-core/wiki/Common-Headers-Parameters#session-token) on passing the session token header. This is implemented in [the JavaScript SDK](https://github.com/dreamfactorysoftware/javascript-sdk) by storing the received `response.session_id` as a `new ApiKeyAuthorization` header that gets passed along with subsequent calls:

```javascript
...
            window.authorizations.add("X-DreamFactory-Session-Token", new ApiKeyAuthorization("X-Dreamfactory-Session-Token", response.session_id, 'header'));
        }, function(response){
...

```

To implement session verification, I recommend making the API calls as normal and trapping for a 401 error response. Then use the 401 as a trigger to login again. This is more efficient than checking for a session before every call. A global error handler for 401s should do the trick.

---

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [May 6, 2015, 7:36am UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/3 "2015-05-06T07:36:40Z")

</div>

Thanks  
That i don"t understand is that  
when code is run on my web serveur (bitnami LAMp) \> login on eqch page  
When code is run localay on my mac \> no problem…

thanks

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [May 6, 2015, 1:15pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/4 "2015-05-06T13:15:50Z")

</div>

If you are logged into the Admin Console in the same browser, the browser will keep passing the admin’s session token with requests, so that you are not prompted for login. I recommend you test using a different browser, a REST client, CURL, or with a separate machine/browser to be sure you’re authenticating and passing headers correctly.

---

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [May 20, 2015, 11:42am UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/5 "2015-05-20T11:42:53Z")

</div>

hi Jeffrey  
still working with the same issue  
based on jqery todo app

here is the code i pu on every page

// session

function checkSession() {

```
$("#loading").show();
// check for existing session, relevant when code is hosted on the dsp
window.df.apis.user.getSession({"body":{}}, function (response) {
    $("#loading").hide();
    // existing session found, assign session token
    // to be used for the session duration
    var session = new ApiKeyAuthorization("X-Dreamfactory-Session-Token",
        response.session_id, 'header');
    window.authorizations.add("X-DreamFactory-Session-Token", session);
    runApp();
}, function (response) {
    $("#loading").hide();
    // no valid session, try to log in
    doLogInDialog();
});

```

}

// my app code

// login dialog

function clearLogIn() {

```
var $_dlg = $('#loginDialog');
$('input', $_dlg).val('');

```

}

function doLogInDialog() {

```
var _message = 'Please enter your User Email and Password below to sign in.';
$('#loginErrorMessage').removeClass('alert-error').empty().html(_message);
clearLogIn();
$("#loginDialog").modal('show').on('shown', function() {
    $('#UserEmail').focus();
});

```

}

function logIn() {

```
var email = $('#UserEmail').val();
var pw = $('#Password').val();
if (!email || !pw) {
    $("#loginErrorMessage").addClass('alert-error').html('You must enter your email address and password to continue.');
    return;
}
var body = {
    "email":email,
    "password":pw
};
$("#loading").show();
window.df.apis.user.login({"body":body}, function (response) {
    // assign session token to be used for the session duration
    var session = new ApiKeyAuthorization("X-Dreamfactory-Session-Token",
        response.session_id, 'header');
    window.authorizations.add("X-DreamFactory-Session-Token", session);
    $("#loginDialog").modal('hide');
    $("#loading").hide();
    runApp();
}, function (response) {
    $("#loading").hide();
    $("#loginErrorMessage").addClass('alert-error').html(getErrorString(response));
});

```

}

Does i miss something? or does the app page should have something different?  
thanks

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [May 26, 2015, 12:41pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/6 "2015-05-26T12:41:30Z")

</div>

> [@jeebee](#):
>
> Does i miss something? or does the app page should have something different?

Is this your question now? Or are you still working on the problem of being prompted for login on every navigation?

---

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [June 10, 2015, 4:05pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/7 "2015-06-10T16:05:57Z")

</div>

Hi Jeffrey  
Still working on my issue  
as i understand I need to use session token header :ok

just for your understanding i will have a Login page  
and after, different page using sdk (with same DSP app)

so my question(s) is (as i’m quite new with dev)  
ok i store response.session\_id as new ApiKeyAuthorization, like the example in the SDL or JqueryTODO app.  
when i jump to my 2nd page how can i use my response.session\_id / ApiKeyAuthorization

thanks very much for helping,

Ps: my DSP is on a Bitnami VM

regards  
julien

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [June 17, 2015, 5:40pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/8 "2015-06-17T17:40:37Z")

</div>

When you jump to your second page, are the SDK functions still defined?

`window.df window.authorizations`

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [June 23, 2015, 2:49pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/9 "2015-06-23T14:49:59Z")

</div>

Hi @jeebee, have you had a chance to check on this?

> When you jump to your second page, are the SDK functions still defined?

> `window.df`  
> `window.authorizations`

---

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [June 23, 2015, 5:43pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/10 "2015-06-23T17:43:22Z")

</div>

hi Jeffrey  
how can i check this ?  
thanks

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [June 23, 2015, 5:58pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/11 "2015-06-23T17:58:57Z")

</div>

Use your browser’s debug console. On the console tab, type the word “window”, and press Enter/Return to see what results appear. You’re looking for df and authorizations (lowercase).

If this is not the method you normally use for debugging your JavaScript, then use whatever tool or process you typically use for this task.

---

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [June 25, 2015, 12:51pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/12 "2015-06-25T12:51:44Z")

</div>

> [@jeffreystables](#):
>
> window

hi Jeffrey  
simply got istart3.html (who is my app page) when i type window

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [June 25, 2015, 4:30pm UTC](https://community.dreamfactory.com/t/javascript-sdk-authentification-login-required-on-each-page/1071/13 "2015-06-25T16:30:52Z")

</div>

Hi @jeebee, thanks for contacting DreamFactory support directly with this issue. For the benefit of the community, I’d like to note that the issue here is that the HTML5 app in question is being designed with multiple pages rather than HTML5 navigation elements, leading to all resources defined on the login HTML page being lost when navigating to a second HTML page.
