Skip to content

Instantly share code, notes, and snippets.

@vseventer
Created March 4, 2014 16:56
Show Gist options
  • Save vseventer/9350470 to your computer and use it in GitHub Desktop.
Save vseventer/9350470 to your computer and use it in GitHub Desktop.
Kinvey JavaScript library for Ember.js: adding an initializer.
// Replace `App Key` and `App Secret` with your application credentials.
var kinveyOptions = {
appKey : 'App Key',
appSecret : 'App Secret',
debug : true // Enable debug mode (development only).
};
// Add the Kinvey initializer.
Ember.Application.initializer({
name : 'kinvey',
initialize : function(container, application) {
// `Kinvey.init` returns a boolean indicating whether there is an
// active user. If so, reload the user to fetch all its attributes
// (username, e-mail, etc.).
var isLoggedIn = Kinvey.init(container, application, kinveyOptions);
if(isLoggedIn) {
Kinvey.getActiveUser().reload();
}
}
});
// Add an additional initializer which injects the active user into your
// controllers and routers. This is optional.
Ember.Application.initializer({
name : 'activeUser',
after : 'kinvey',
initialize : function(container, application) {
application.inject('controller', 'activeUser', 'user:active');
application.inject('router', 'activeUser', 'user:active');
}
});
// Create the application.
var App = Ember.Application.create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment