npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-devise-simple-auth

v0.6.0

Published

Devise integration for ember using ember-cli

Downloads

15

Readme

ember-devise-simple-auth

A plugin that allows an Ember app to integrate with a (mostly stock) Devise setup.

What it does

Provides the necessary Ember plumbing to integrate with an out-of-the-box Devise setup. This means it uses cookies for session storage, but does not perform any redirects.

Provides

app/routes/session.js - The route that handles sign in. You will need to create a template named sessions.

app/models/authenticator.js - A plain object that provides the current signed-in state, along with methods to sign in/out and lookup the current user.

config/initializers/authenticator.js - Injects the authenticator into your routes & controllers so you have access to the signed-in state anywhere you are!

config/initializers/csrf.js - jQuery ajax response handler that reads new CSRF tokens handed in from devise (see [companion gem][companion_gem]).

config/initializers/session-route.js - Adds a route named "session" to your app's router. The path defaults to /sign-in but [is configurable][configurable].

config/plugin.js - The main file that loads the plugin. Extends the base Ember.Route with some auth-related action handlers. Extends Ember.Controller with properties for signed-in state.

Installing

Currently this plugin works best with apps built with either ember-appkit-rails or ember-rails. We hope to be adding support for ember-app-kit in the near future.

Install client-side code with bower

bower install ember-devise-simple-auth

Note: Even though there is a gem associated with this plugin, you will still need to install the client-side code associated with this plugin. It is managed by the Bower package manager. Here are instructions for setting up Bower in a Rails app. If you do not want to use Bower, then you can download an index.js files for either ember-rails or ember-appkit-rails and place it in vendor/assets/javascripts/ember-devise-simple-auth/index.js.

Install gem for server-side support

To support some small customizations in Devise::SessionsController you need to install our gem and update your routes. Add the following to your Gemfile:

gem "ember_devise_simple_auth"

Then run:

bundle install
rails g ember_devise_simple_auth:install

ember-rails apps

In config/application.js add the following:

//... vendor requires
//= require ember-devise-simple-auth/globals
//... the rest of your requires

ember-appkit-rails apps

In config/application.js add the following:

//... vendor requires
//= require router
//= require ember-devise-simple-auth/appkit
//... the rest of your requires
//= require_self

require('ember-devise-simple-auth');

NOTE: Make sure you require the router before ember-devise-simple-auth

Configuring

There are a few options you can specify now, and more to come in the future. If there's something you need to configure but can't figure out how, please open an issue describing what you needa nd we'll see if we can provide it.

Configuration happens in config/application.js as part of the call to create():

window.App = require('app').default.create({
  deviseEmberAuth: {
    signInPath: "/sign-in", // the URL users will see in the browser for the sign in page
    userModelType: "user", // **ember-data only** name of the model that represents your user; same thing you'd pass to `store.find("...")` in a route
    deviseSignInPath: "/users/sign_in", // the URL to POST to for creating a session
    deviseSignOutPath: "/users/sign_out", // the URL to DELETE to for signing out
    currentSessionPath: "/sessions/current" // the URL for getting the current signed-in state; this is currently added by the gem
  }
});

In the Wild

For a real-world example of ember-devise-simple-auth in use, check out facturas by @abuiles.

Usage

NOTE: This assumes you have configured Devise and followed the instructions above in [Installation][installation].

The only thing you need to do is provide a template named session (for eak-rails that would be app/templates/session.hbs). Then assign {{action signIn}} to a button or form and you should be good to go.

Common Tasks

There are a few actions that you can choose to handle in your application's routes if you need to override the default behavior.

Redirect After Sign In

To transition to another route on successful sign in, you can handle the validSignIn action in your application route. For example:

export default Ember.Route.extend({
  actions: {
    validSignIn: function() {
      this.transitionTo("dashboard");
    }
  }
});

Handle Failed Sign In

If a user enters invalid credentials, you can handle the invalidSignIn action. For example:

export default Ember.Route.extend({
  actions: {
    invalidSignIn: function() {
      this.controllerFor("application").set("errorMessage", "Invalid credentials");
    }
  }
});

Customize Transition on Sign Out

On sign out, ember-devise-simple-auth automatically transitions back to sign in. If you prefer it goes somehwere different, you can handle the didSignOut action:

export default Ember.Route.extend({
  actions: {
    didSignOut: function() {
      this.transitionTo("home");
    }
  }
});

Log Unauthorized Requests

Anytime an unauthorized request is made, ember-devise-simple-auth will send an unauthorizedRequest action. By default, this action transitions back to sign in, but you can override it to do something else first.

export default Ember.Route.extend({
  actions: {
    unauthorizedRequest: function(original) {
      this.logAction("unauthorizedRequest");
      original();
    }
  }
});

Display information about currently signed-in user

You can access a currentUser property in any template to get details about the current user. If you are using ember-data, this will deserialize the /sessions/current response (provided by the support gem) using a configurable model name (defaults to "user").

For example, assuming you have a fullName & email property on your user model, you can say:

Signed in as: {{currentUser.fullName}} ({{currentUser.email}})

©2014 D-I