Fix `RuntimeError: Could not find a valid mapping for nil`

Steps to reproduce the bug:

1. Open two pages under masqueraded user 
2. Turn off (back) masquerading on the first page
3. Try to turn off masquerading on the second page

After that you will see `RuntimeError: Could not find a valid mapping for nil` because user id from session is nil.