Ember / Rails CORS Simple-Auth 405 (not allowed)

I have an ember-cli app with ActiveModelAdapter for Rails API using rack-cors . I have configured for both ember-cli-simple-auth-devise .

Locally in development everything works fine. But as soon as I deploy my ember-cli app on Heroku, I cannot authenticate my signin, but I can get other entries. I am getting the following 405 error:

POST http://example.herokuapp.com/businesses/sign_in 405 (not allowed)

Perhaps this is because I'm using Business instead of User for my Devise model, but I'm changing User to Business in application_controller (plus this won't work locally otherwise):

## /backend/app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
 before_filter :authenticate_user_from_token!

 private

 def authenticate_user_from_token!
   authenticate_with_http_token do |token, options|
     user_email = options[:user_email].presence
     user       = user_email && Business.find_by_email(user_email) 
     ## /\ Changed User to Business /\

     if user && Devise.secure_compare(user.authentication_token, token)
       sign_in user, store: false
     end
   end
 end
end

      

Rack configuration:

## /backend/config.ru

require ::File.expand_path('../config/environment',  __FILE__)
run Rails.application

require 'rack/cors'
use Rack::Cors do

  # allow all origins in development
  allow do
    origins '*'
    resource '*', 
        :headers => :any, 
        :methods => [:get, :post, :delete, :put, :options]
  end
end

      

I configured simple-auth-devise like this:

// frontend/config/environment.js

ENV['simple-auth-devise'] = {
    serverTokenEndpoint: 'businesses/sign_in',
    resourceName: 'business',
    crossOriginWhitelist: ['http://example-backend.herokuapp.com/']
};

      

Any insight on this would be much appreciated.

Thank!

** Update ** I've narrowed it down to POST to example.herokuapp.com and not my backend url example-backend.herokuapp.com. So I think it has something to do with ember-cli-simple-auth not using a proxy that I installed with hero as the store does.

+3


source to share


1 answer


You need to configure serverTokenEndpoint

including the host if the host is not the one the Ember app is served to:



ENV['simple-auth-devise'] = {
  serverTokenEndpoint:  'http://example-backend.herokuapp.com/businesses/sign_in',
  resourceName:         'business',
  crossOriginWhitelist: ['http://example-backend.herokuapp.com/']
};

      

+2


source







All Articles