maxjustus / sinatra-authentication

A sinatra extension wrapped in a gem that implements authentication/permissions with users stored in the database. Now with optional support for facebook connect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

current_user not being created

mhuebert opened this issue · comments

I'm using the latest versions of DM, Sinatra and sinatra-authentication and I am perplexed by a recurrent problem with the current_user object not being created. This causes a server error when I have -if current_user.admin? in my templates (no method 'admin' for nil:nilClass).

When it occurs, the only predictable thing I can do to get my site back running is remove all references to current_user from my templates. The /login and /logout pages still work. The problem seems to go away and come back at will; I haven't yet detected the pattern.

Can anyone think of what might prevent current_user from being created? I am a novice at this so I may be missing something obvious.

Thankyou muchly.

Strange.. The only times I get that error are when I'm switching database backends and the browser session is referencing a user id that doesn't exist.. Manually going to /logout and logging back in fixes it for me. Seems to me your issue might be a bit different though. Are you possibly using the auto_migrate! method somewhere in your code? That'll wipe out your database whenever it's run.

Hmm, interesting. Next time it happens I will try this. I am using auto_upgrade! but have been periodically using using auto_migrate! in the process of troubleshooting. It's possible that while troubleshooting other problems I'm causing this one. I'll spend another day coding and see what happens. Thanks for the pointer!

Another thought, would it make sense for current_user to default to guest in situations like this?

This happened again, and manually logging out worked to solve it.... thanks again.

No problem! I suppose current_user ought to default to a guest instance.. I'll look into it.