Search code examples
ember.jsember-simple-auth

Stub authentication server used by ember-simple-auth during development


I'm using ember-simple-auth in my emberjs app to authenticate via oauth2-password-grant with my own (currently unimplemented) service.

I'd like to continue developing the front-end before creating the authentication service.

Can the authentication service be stubbed so login/logout features can be used? I'm aware that I mock it with http-mock during tests, but I would also like to work on the front-end design and view it in the browser.


Solution

  • HTTP mocks also run during development. You can also use Pretender or Mirage (a library built on top of Pretender) to clientside mocks.

    In Mirage your route may look something like this:

    // app/mirage/config.js
    this.post('/users/sign_in', (db, request) => {
      return {
        user_email: "some.user@gmail.com",
        user_id: 1,
        user_token: "LcsBEYP2yjTcc-G7drto"
      };
    });
    

    depending on the shape of your backend response.