# Nonstop Javascript SDK

## Users

### Login

`login` should be called whenever a user Registers or Signs In via OneID, after the call to create or update the user in ShowMS.

Thus the flow is:

OneID Success -> ShowMS Success -> Nonstop Success -> Control Returned to Client

In order to call `login`, create a `userInput` model:

```javascript
    const userInput = {
        firstName: 'Dave',
        externalId: 'showms-user-id',
        email: 'dave@stormideas.com',
        birthday: '1988-01-19'
    };
```

* **firstName** - should be the user's first name as returned by OneID
* **externalId** - should be the ShowMS User ID
* **email** - email address from OneID. This will be securely hashed and is used to find the user in the admin for customer service scenarios.
* **birthday** - the user's birthday as returned from OneID in the format 'YYYY-MM-DD'

And pass this into the login function:

```javascript
    Nonstop.default.login(userInput)
        .then((createdUser) => {
            // Nonstop user successfully logged in
        })
        .catch(() => {
            // Error logging in Nonstop user
        });
```

If the user should gain a reward by logging in then the SDK will play the appropriate animation before handing control back to the calling app.

Note: You can optionally pass an additional parameter:

```javascript
    Nonstop.default.login(userInput, true);
```

To suppress any Reward Animation as a result of login. The main use case for this is when already logged in existing users need to be logged into Nonstop in the background as part of the upgrade path.

On error the client should message the user and offer to retry.

The `createdUser` object returned with Success will have details of logged in user's:

* id
* name
* points

But there should be no need to store this on the client app. While logged in the current user can be accessed via the SDK at all times via:

### Is Connected

You can ask whether there is a currently logged in user via:

```javascript
    Nonstop.default.isConnected();
```

### Current User

You can access the currently logged in user via:

```javascript
    Nonstop.default.currentUser();
```

### Logout

`logout` should be called whenever a user logs out of OneID.

```javascript
    Nonstop.logout();
```

This method is synchronous and so does not return a promise.