# meteorhacks-login-state

> nodejs module for meteorhacks:login-state package

Latest version **0.0.1** (published 2015-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install meteorhacks-login-state
pnpm add meteorhacks-login-state
yarn add meteorhacks-login-state
bun add meteorhacks-login-state
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2015-07-02 |
| First published | 2015-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Maintainers | thinkholic |
| Keywords | meteor, meteorhacks |

## Links

- npm: https://www.npmjs.com/package/meteorhacks-login-state
- Repository: https://github.com/meteorhacks/login-state
- Issues: https://github.com/meteorhacks/login-state
- npm.io page: https://npm.io/package/meteorhacks-login-state

## Recent versions

- 0.0.1 (latest) — 2015-07-02

## README

# Login State

Share Login State between the Sub Domains for Meteor Apps (Support for static apps too)

## Getting Started

This meteor package use for sharing login state information between apps hosted in different sub-domains. All apps are not necessory to be meteor apps. One app must be a meteor app and its login state can be share easialy across multiple sub-domains using this package.

### On Meteor App

#### Inatall

`meteor add meteorhacks:login-state`

#### Configuration

Update `settings.json` as follows. You need to provide appropriate values for `domain` and `cookineName` fields.

> Note: You must have update the `domain` field in `settings.json`, with the domain name which you need to share login state. 
> Eg: When your domain name and landing page is `mysite.com` and `app.mysite.com` is your app subdomain and, also `supports.mysite.com` is the support forum, then you need to update `domain` field as `.mysite.com`.

```json
{
  "public": {
    "loginState": {
      "domain": ".your-domain-name.com",
      "cookieName": "app-login-state-cookie-name"
    }
  }
}
```

### On static app

#### Using custom JavaScript code


Create a JavaScript file as `js/login_state.js` or given a name as you want. After that update following code there.

```javascript
LoginState = {};

LoginState.get = function(cookieName) {
  var loginState = getCookie(cookieName);
  if(loginState) {
    return JSON.parse(decodeURIComponent(loginState));
  } else {
    return false;
  }
};

function getCookie(cname) {
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1);
      if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
  }
  return "";
}
```

Include it into your html document. Then you can call `LoginState.get(cookieName)` function to get login state by providing the correct cookie name.

Here's the sample code for that;

```javascript
var loginState = LoginState.get("app-login-state-cookie-name");
if(loginState) {
  // the user has loggedIn to the meteor app
  // see the loginState Object for the addtional data
  // (append your code here!)
  console.log(loginState);
} else {
  // user has not loggedIn yet.
  // (append your code here!) 
}
```

#### Installing via bower

`bower install meteorhacks-login-state`

> See: [bower](http://bower.io/)

#### Installing via Browserify

`npm install meteorhacks-login-state`

Browsers doesn't allow to run nodejs modules directly. So, you need to use [browserify](http://browserify.org/) for that.

---
_Source: https://npm.io/package/meteorhacks-login-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
