heartsentwined / ember-auth

Authentication framework for ember.js.
http://ember-auth.herokuapp.com/
397 stars 43 forks source link

How to make it work with ember app kit? #120

Open mattbeedle opened 11 years ago

mattbeedle commented 11 years ago

I've been trying to build a recipe app called tasti.ly using ember app kit, but I've run into some issues with ember-auth. Including any of the adapters/modules seems to throw an error. I set up a blank app to show this issue:

https://github.com/mattbeedle/ember-app-kit-ember-auth

heartsentwined commented 11 years ago

Edit: sorry, somehow missed the links. I have no experience with using ember-app-kit previously but I'll try the getting started guide and see if I can familiarize myself enough to see what's wrong

mattbeedle commented 11 years ago

Thanks, that would be a great help! I'm also looking at it right now, but I'm at a bit of a loss. You should be able to just pull the repo link above and then run:

npm install -g grunt-cli && npm install && npm install -g bower && bower install && grunt server

to get it up and running.

heartsentwined commented 11 years ago

Actually if you have a node.js friend (s)he might be able to tell you more about what's wrong. I'm a rails coder, so I'll try, but I guess I'm in an even worse position than you to see through the problem.

heartsentwined commented 11 years ago

One thing came up to mind though, does the npm packages need anything specific? e.g. export stuff to somewhere? wrapped in some sort of module? At present the npm packages will just serve the repo - dist files in dist/.

mattbeedle commented 11 years ago

I don't know any node people unfortunately :S. I'm also a ruby guy mainly, but it seemed wrong to me to have rails as a dependency when it's just a javascript app and the API on a different server. It should function in exactly the same way as a rails app though. The public/index.html file is where I manually included the scripts from the dist folders. The server just runs on port 8000 and serves up the static js app.

The only thing that is different on the javascript side from a standard ember-rails app I think is that app-kit uses modules.

heartsentwined commented 11 years ago

Ah, too bad, we're both in the dark then :-( I'll update you if I get anything, but no luck so far

mattbeedle commented 11 years ago

What should

get$(this, 'auth')

return? On this line: https://github.com/heartsentwined/ember-auth-request-jquery/blob/master/dist/ember-auth-request-jquery.js#L27

And where is that getting set? I can reproduce the error from chrome console by typing:

App.__container__.lookup('authRequest:jquery')
mattbeedle commented 11 years ago

it's undefined for me

mattbeedle commented 11 years ago

I think if I can just figure out what that is and where it's getting assigned, I can fix all of the module/adapter loading.

digitalplaywright commented 11 years ago

@mattbeedle You might be missing some required ember-auth modules. A good starting point could be to install the bower equivalents of the modules from the ember-auth-rails-demo gemfile (https://github.com/heartsentwined/ember-auth-rails-demo), like e.g:

gem 'ember-auth-rails', '~> 5.0' # client-side authentication
gem 'ember-auth-request-jquery-rails', '~> 1.0' # auth requests via jQuery.ajax
gem 'ember-auth-response-json-rails', '~> 1.0' # responses in json
gem 'ember-auth-strategy-token-rails', '~> 1.0' # token authentication
gem 'ember-auth-session-cookie-rails', '~> 1.0' # use cookies
gem 'ember-auth-module-ember_data-rails', '~> 1.0' # ember-data integration
gem 'ember-auth-module-auth_redirectable-rails', '~> 1.0' # auth-only routes
gem 'ember-auth-module-action_redirectable-rails', '~> 1.0' # post- sign in/out redirect
gem 'ember-auth-module-rememberable-rails', '~> 1.0' # remember me

As a side note it might be helpful to new users if the ember-auth error message when dependencies are missing would print out a console message in addition to returning undefined.

Please keep us update on your progress as I am also interested in getting ember-auth to work with ember appkit.

stefanpenner commented 11 years ago

re: EAK -> http://iamstef.net/ember-app-kit/guides/getting-started.html

mattbeedle commented 11 years ago

@digitalplaywright thanks for the response. I don't think that's the case though. I installed all of the ones that I needed with bower and they are all included in public/index.html. I only left out url-authenticatable as I don't want to allow that strategy. From looking at the ember-auth source though, if a module isn't included everything should still work and it should raise a not implemented error when trying to use missing functionality:

https://github.com/heartsentwined/ember-auth/blob/master/lib/request.em#L3

I'll try adding the final missing url-authenticatable module just in case it helps though.

stefanpenner commented 11 years ago

Also, @heartsentwined if issues exist, i would like to work with you to make it as frictionless as possible.

heartsentwined commented 11 years ago

@stefanpenner most likely ember-auth's problem first - must it be written AMD-style, or some other "export"-ish requirements? Currently the npm packages just distribute the repos themselves - "dist files live in /dist".

heartsentwined commented 11 years ago

@mattbeedle there used to be sanity check error messages during 9.x development, but they got removed due to them causing infinite-loop bugs (auth depends on jquery request adapter; jquery request adapter depends on auth; etc). I'll try to put them back in if I can find a way around it.

heartsentwined commented 11 years ago

Also see #112 for a case of stuff being undefined.

digitalplaywright commented 11 years ago

@heartsentwined: @hjdivad and I created an example client app with ember auth v8 using ember auth easy, and it is working great:

However, we had problems getting vanilla ember auth v9 to work:

We might just be missing something obvious in how to get v9 to work, but any help is appreciated. Is ember auth v9 more a work in progress or do you have some tips on what we are doing wrong?

We have created an example token api server using rails and devise, that can be used together with these ember client examples:

ralfschimmel commented 10 years ago

I am having the exact same problem @mattbeedle is having. The 'auth' property of the Em.Auth.AuthRequest seems to be 'undefined'. Did anyone find a workaround for this issue?

digitalplaywright commented 10 years ago

@ralfschimmel @mattbeedle I have not been able to get ember auth v9 to work, but v8 works fine for me. This might just be because I have not spent enough time on the problem.

If you want to use ember auth v8 then ember auth easy (https://github.com/mharris717/ember-auth-easy) does a lot of the heavy lifting for you, and will probably save you some time.

ralfschimmel commented 10 years ago

@digitalplaywright does that also work with the latest ember and ember-data?

I am using the latest version of EAK.

digitalplaywright commented 10 years ago

@ralfschimmel Yes.

If you want to quickly test-run ember auth easy @mharris717 just added a generator that will generate an ember app kit application that uses ember auth together with ember auth easy. I have not tried this generator myself, but it seems quite handy.

ralfschimmel commented 10 years ago

Ok tnx @digitalplaywright.

I have a complete project running in production using ember-auth, but I switched to EAK. Now ember-auth is not working, and just dropping in ember-auth-easy seems strange, since I already have all the templates, controllers, etc. Can I just use my old config?

I'm still hoping @heartsentwined can shed some light on using v9 with EAK.

digitalplaywright commented 10 years ago

@ralfschimmel What ember auth easy does for you is provide the user model, controller, and partial templates. If you already have those components in place and working then I don't see a great reason to switch unless you just want to make this a concern in the same way devise is a concern in rails.

For anyone that is interested. See the ember auth easy README for how to use the generator that generates an ember app kit application that use ember auth together ember auth easy .

ralfschimmel commented 10 years ago

@digitalplaywright the problem is that ember-auth (v8 or v9) is not working when used with EAK. I just can't seem to get either of the two working and am on the brink of rolling my own auth.

mattbeedle commented 10 years ago

@digitalplaywright @ralfschimmel I dropped down to ember-auth v8 as well. It seems to me that ember-auth-easy doesn't really have anything to do with this issue. If you use ember-auth v8 it works, if you use ember-auth v9 it doesn't.

There are a couple of issues using v8 with the latest ember-data though, depending on what functionality you are using. You will not be able to get the current user using Auth.get('user'), or see if the user is signed in with Auth.get('signedIn'). I had to go through my code and change occurrences of

Auth.get('user')

to

@store.find('user', Auth.get('userId'))

Also, you may not start variable names with capital letters in templates. So anything starting with Auth in the template will break things. The latest ember auth is injected into all controllers and routes automatically, so in the view you get a lower case auth variable which would be ok. There may have been some other small things.

mattbeedle commented 10 years ago

What are the issues you are having with v8 @ralfschimmel ? Maybe I can point you in the right direction.

mharris717 commented 10 years ago

All,

Thanks for the interest / pointers to Ember Auth Easy. I'll check the thread out and leave my comments shortly, hopefully I can help.