ufront / ufront-easyauth

Easy database-driven authentication for ufront. Each group is assigned permissions, and each user can belong to certain groups.
MIT License
1 stars 2 forks source link

EasyAuth login and create user usage issue #6

Open zaynyatyi opened 9 years ago

zaynyatyi commented 9 years ago

I'm trying to use easyAuthApi and started getting that

RServerSideException(com.nailedgames.tzd.app.api.SignupApi.loginUser(zbot01,123456), Trying to access session data before init() has been run, Called from ufront/web/session/FileSession.hx line 329 Called from ufront/auth/EasyAuth.hx line 152 Called from ufront/auth/EasyAuth.hx line 139 Called from ufront/auth/api/EasyAuthApi.hx line 30 Called from com/nailedgames/tzd/app/api/SignupApi.hx line 43 Called from a C function Called from ufront/api/UFAsyncApi.hx line 95 Called from ufront/api/UFAsyncApi.hx line 140)

The code is just

public function loginUser(name:String, password:String):Int { authApi.attemptLogin(name, password).sure(); ufTrace("logged in:" + auth.isLoggedIn()); return 0; }

how should i init auth Api or session?

zaynyatyi commented 9 years ago

I injected FileSession, called init() before login and commit() after. So i logged in. But then in controller i called requireLogin() and it throws me an error that i'm not logged in. I injected FileSession into controller too and called init() before requireLogin() call.

I think we need at least brief documentation for session.

Btw, cacheSession init() throwed an error.

zaynyatyi commented 9 years ago

I added sessionImplementation: FileSession, to UFrontApplication, but how can i get it in my Api class implementation? How should it be initialized?

jasononeil commented 9 years ago

Sorry for the late reply. I'll try post a more complete example later, but the easiest work around now is probably:

InlineSessionMiddleware.alwaysStart = true;

See http://api.ufront.net/ufront/web/session/InlineSessionMiddleware.html

Basically this middleware runs and will call init() and commit() on your sessions, but usually only after a session has been started manually. If you change alwaysStart to true, then it starts on each visit.

I'll get back to this with an example of how to start it manually when I can.

kevinresol commented 9 years ago

I dunno why, but I have been using the login function for a while and it worked fine without manually initiating anything. But recently I got the same error as @zaynyatyi. InlineSessionMiddleware.alwaysStart = true; does get rid of the error, but it is saving a "null.sess" file instead. See https://github.com/ufront/ufront-mvc/issues/25