Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-ted-session

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-ted-session

Easy user session management for your TED application

  • 0.0.1
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Ember-ted-session

This addon allows your Ember app to quickly pull in session based data, like current user, from your TED backend.

Requirements

  • JSONAPI
  • Your application must have a User model.

Install

ember install ember-ted-session

Usage

Current user

As soon as your application boots up you'll probably want to fetch the current user. The ted-session service has a #fetch method for that.

// application/route.js

export default Ember.Route.extend({
  tedSession: Ember.inject.service(),

  beforeModel() {
    this.get('tedSession').fetch();
  }
});

Now any component can access the current user by just injecting the service.

// my-widget/component.js

export default Ember.Component.exnted({
  tedSession: Ember.inject.service(),
  currentUser: Ember.computed.readOnly('tedSession.currentUser')
});

Logging in

If you want to build a login form to let users login you can use the ted-session model to authenticate with the backend.

// login/route.js

export default Ember.Route.extend({
  tedSession: Ember.inject.service(),

  actions: {
    login(email, password) {
      this.get('tedSession')
        .login(email, password)
        .then(() => console.log('it worked'))
        .catch(() => console.loa('nope'));
    }
  }
});
Session service API
APITypeAboutReturnsExample
fetch()functionFetches the current user from the backendPromisetedSessionService.fetch()
terminate()functionTells the backend to log the current user outPromisetedSessionService.terminate()
login(email, password)functionLogs in the userPromisetedSessionService.login('rt@ted.com', 'password');
currentUserpropertyReturns the current userUser DS.ModeltedSession.get('currentUser')
isLoggedInpropertyIs there a current userBooleantedSession.get('isLoggedIn')
isNotLoggedInpropertyIs there no current userBooleantedSession.get('isNotLoggedIn')

Details

Payload

The get expects a JSON API document.

// GET ted-sessions/current

{
  "data": {
    "id": "current",
    "type": "ted-sessions",
    "links": {
      "self": "/ted-sessions/current"
    },
    "attributes": {
      "csrf-token": "token"
    },
    "relationships": {
      "user": {
        "links": {
          "self": "/ted-sessions/current/relationships/user",
          "related": "/ted-sessions/current/user"
        }
      }
    }
  }
}

The post however is formatted to match the JSON that a normal devise session controller would expect.

// POST ted-sessions/current

user: {
  email: "email",
  password: "password"
}
CSRF token

If your response payload includes an attribute called csrf-token then it will be used as the X-CSRF-TOKEN in all future XHR requests.

Keywords

FAQs

Package last updated on 27 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc