# How much should a service know about routing?

**URL:** <https://discuss.emberjs.com/t/how-much-should-a-service-know-about-routing/7101>\
**Category:** Uncategorized\
**Created:** [January 17, 2015, 7:03pm UTC](https://discuss.emberjs.com/t/how-much-should-a-service-know-about-routing/7101 "2015-01-17T19:03:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesarosen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamesarosen/32/3535_2.png) [@jamesarosen](https://discuss.emberjs.com/u/jamesarosen)\
**Post date:** [January 17, 2015, 7:03pm UTC](https://discuss.emberjs.com/t/how-much-should-a-service-know-about-routing/7101/1 "2015-01-17T19:03:47Z")

</div>

I’m trying to convert our current authentication controller into a service on the path to Ember 2 compatibility. I’m having some trouble converting the following:

```auto
actions: {
  checkCredentials: function() {
    Ember.$.post("/login", {
      user: this.get("email"),
      password: this.get("password")
    }).then(
      this._onCredentialsValid.bind(this),
      this._onCrednetialsInvalid.bind(this)
    );
  }
},

_onCredentialsValid: function(json) {
  if (json.needs_two_factor_auth ) {
    this.transitionToRoute('authentication.two-factor');
    return;
  } else {
    this.get('currentCustomer').setProperties(json.customer);
    this.get('currentUser').setProperties(json.user);
  }
}

```

That is, the `authentication.sign-in` controller renders an email/password form. When the user submit it, the controller submits the credentials. If they’re valid, it checks whether two-factor authentication is required. If it is, it redirects to `authentication.two-factor`.

It can do that redirect because `Ember.Controller` has `transitionTo`. But my service won’t have that.

Should I just inject the router into the service in an initializer?

```auto
export default {
  name: "add-router-to-auth-service",

  initialize: function(_, app) {
    app.inject('service:authentication', 'router', 'router:main');
  }
};

```

Or is there some other pattern that would be more appropriate?

---

<div class="post-metadata">

**Author:** ![MiguelMadero](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/miguelmadero/32/15187_2.png) [@MiguelMadero](https://discuss.emberjs.com/u/MiguelMadero)\
**Post date:** [January 18, 2015, 6:31pm UTC](https://discuss.emberjs.com/t/how-much-should-a-service-know-about-routing/7101/2 "2015-01-18T18:31:12Z")

</div>

I think that might be ok for now. in the future I will expect the router to be just another service (just like the store). We have similar use cases for services needing the router and also link-to depends on it, which makes it super hacky.
