# Detecting user already logged in when using SSO

**URL:** https://meta.discourse.org/t/detecting-user-already-logged-in-when-using-sso/26968
**Category:** Feature
**Tags:** sso, discourseconnect
**Created:** [2015 年 3 月 30 日午前 12:21 UTC](https://meta.discourse.org/t/detecting-user-already-logged-in-when-using-sso/26968 "2015-03-30T00:21:02Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2015 年 3 月 30 日午前 5:31 UTC](https://meta.discourse.org/t/detecting-user-already-logged-in-when-using-sso/26968/9 "2015-03-30T05:31:11Z")

</div>

So, have Discourse have a `</body>` script that goes like this:

```plaintext
if (!Discourse.User.currentProp('username') {
    $.ajax(....., {
        ....
        dataType: "jsonp",
        success: function(xhr) {
            if (xhr.responseJSON.have_account) {
                window.location = "/session/sso";
            }
        }
    });
}

```

It fails open - if the main site is down, the user can continue to browse as an anon on Discourse.

---

_[View the full topic](https://meta.discourse.org/t/detecting-user-already-logged-in-when-using-sso/26968)._
