4

I'm building a app using emberjs and active_model_serializer.

I searched a lot to find out on how to implement the authentication/authorization with emberjs and rails, but couldn't.

Has anyone done this?

1 Answer 1

3

I am currently working on this kind of topic: I am using Devise, and have tried two kind of solutions:

  1. Either use navigation for auth, delegating the whole process to Devise's standard controllers & views,
  2. Or you can wrap Devise's controllers to return JSON to a pure single page application.

I tried both and all is working well. To inconvenient with #1 is the 'old fashioned' blink at auth navigation. Solution #2 has my preference.

Here is an example of Devise auth wrapping in JSON:

class SessionsController < Devise::SessionsController

  def create
    resource = warden.authenticate!(auth_options)
    sign_in(resource_name, resource)
    render(json: resource, status: :ok) and return
  end

  ...

The point that is still annoying me is that I had to completely override controller method, to avoid double rendering, as Devise is not yet designed to have customizable rendering.

Sign up to request clarification or add additional context in comments.

1 Comment

do you want leave a brief code example of option 2 to make your answer much clearer. @Millisami if you have solved this, do you mind updating your question with your answer. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.