lynndylanhurley / j-toker

Simple, secure token authentication for jQuery.
Do What The F*ck You Want To Public License
173 stars 46 forks source link

Using J-toker while server side rendering fails due to JSExec error #18

Open throoze opened 8 years ago

throoze commented 8 years ago

Hi! I had to give up using J-Toker because while server side rendering it encounter some issues due to some of its dependencies. This is the (JSExec) error:

TypeError: Object function ( w ) {
                if ( !w.document ) {
                    throw new Error( "jQuery requires a window with a document" );
                }
                return factory( w );
            } has no method 'extend'

I know it's not priority one, but I hope you can figure something out to make it work without the offending dependency. Right now I'm super busy trying to finish this project, but when I'm done, I'll try to contribute. If you guys figure something out, please let me know!

I'm using Ruby on Rails with react-rails, devise_token_auth, flux and browserify. You can find the repo here if you want to reproduce the error and the setup.

lynndylanhurley commented 8 years ago

Hi, I'm about to release a library that should address this. It uses isomorphic-fetch instead of jQuery.ajax, and it will come with a server-side rendering example.

throoze commented 8 years ago

That's good news! any estimate time of release? please let me know! Yes, I've come to realize that jQuery was the origin of the issue, since it depends on a document element. which doesn't exist on the server side. I tried using jQuery version ^2.1.4 with jsdom@3.1.2 which was supposed to work on the server side, but didn't get any result. I kept getting the same error. Maybe j-Toker uses its own version internally.

lynndylanhurley commented 8 years ago

@throoze - i'm literally writing the last test now. I'll need to finish the documentation and launch the example app to heroku, and that's it.

throoze commented 8 years ago

Excellent! Please let me know when its released and I'll be your first beta tester lol

lynndylanhurley commented 8 years ago

Ok I think this is ready for beta testing: https://github.com/lynndylanhurley/redux-auth

Please check it out and let me know if you have any feedback :smiley:

throoze commented 8 years ago

Thanks! one thing is, i'm not using redux, but instead vanilla flux, is redux required for using this library?

lynndylanhurley commented 8 years ago

Yeah it's a requirement. Sorry!