# Accessing login page via jQuery

**URL:** <https://forums.knack.com/t/accessing-login-page-via-jquery/7548>\
**Category:** API & Custom Code\
**Created:** [September 20, 2016, 11:00pm UTC](https://forums.knack.com/t/accessing-login-page-via-jquery/7548 "2016-09-20T23:00:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrzejlap30167](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Andrzejlap30167](https://forums.knack.com/u/Andrzejlap30167)\
**Post date:** [September 20, 2016, 11:00pm UTC](https://forums.knack.com/t/accessing-login-page-via-jquery/7548/1 "2016-09-20T23:00:33Z")

</div>

Problem:

I have created page (let's say scene\_1 called "Portal") and setup it as login protected within Knack environment. The result is that Knack created new parted page to my scene\_1 and called it "Portal Login" with key: scene\_2.

Now I want to put some Java code on this scene\_2 page. Knack environment says it has one view called let's say view\_5. I can put some code on this view\_5 like:

```
$(document).on('knack-view-render.view_5', function(event, view, data) { 
  mixpanel.track("Login", {"Page name":"Portal Login"});
});
```

Whne I check logs I see that this view\_5 is on scene\_2 (login page). But when I want to create something like:

```
$(document).on('knack-scene-render.any', function(event, page) {

var firstview = page.views[0].key; //normally find the key for first view on page

if (firstview = “view\_5”) {

```
//something

```

}  
else { // another action  
}

});
```

it never finds my view\_5. I found out from logs that in the page.view[] table on login page are views from scene\_1 not from scene\_2.

So I cannot recognize the login form by using callback on rendering pages.

Any idea how make a workaround?

thanks in advance.

Andrzej

---

<div class="post-metadata">

**Author:** ![Andrzejlap30167](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Andrzejlap30167](https://forums.knack.com/u/Andrzejlap30167)\
**Post date:** [September 21, 2016, 8:06pm UTC](https://forums.knack.com/t/accessing-login-page-via-jquery/7548/2 "2016-09-21T20:06:40Z")

</div>

OK,

I have found easy solution by using Knack.getUserAttributes().

```
var user = Knack.getUserAttributes();
if (user.email == null){
  // this means that User is on login page, so I logout him from tracking codes
  tracking.reset();
}
else {
  // this mean that User is already logged in, so he is not on login page
  // as he might just log in I am calling identify tracing code
  tracing.identify();
}
```

'tracking' is an example, but most tracking platforms have similar functions.

Andrzej
