Giter Site home page Giter Site logo

meteor-login-state's Introduction

Login State

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

Getting Started

Using kadira:login-state you can share the login 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

Install

meteor add kadira: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.

{
  "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.

If this is an another meteor app, you don't have to create this manually. You just need to install the kadira:login-state package, and call the LoginState.get(<cookieName>) function with the correct cookie name.

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;

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!)
}

Content of the loginState will be something like this. It won't have any sensitive information like passwords or loginTokens.

{
  timestamp: 1435835751489,
  username: "username",
  userId: "meteor-user-id",
  email: "[email protected]"
  url: "https://ui.kadira.io"
}

Installing via bower

bower install meteor-login-state

See: bower

Installing via Browserify

npm install meteor-login-state

Browsers doesn't allow to run nodejs modules directly. So, you need to use browserify for that.

meteor-login-state's People

Contributors

arunoda avatar heimdallrj avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.