Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maybeAuthId and maybeAuth may be inconsistent #486

Closed
meteficha opened this issue Jan 17, 2013 · 12 comments
Closed

maybeAuthId and maybeAuth may be inconsistent #486

meteficha opened this issue Jan 17, 2013 · 12 comments

Comments

@meteficha
Copy link
Member

I'd expect the following property consistent to always hold.

consistent = do
  (a,b) <- runDB $ (,) <$> maybeAuthId <*> maybeAuth
  isJust a `shouldBe` isJust b

Unfortunately, it may not hold on some corner cases (although not corner enough that they were already seen):

  1. User A logs in.
  2. User A is removed from the database (cookies are not cleared).
  3. User A visits the site.

I don't see any way of fixing this bug besides doing a roundtrip to the DB on maybeAuthId, but it is not desirable to do so in general. Thoughts?

@snoyberg
Copy link
Member

I've actually run into this myself on occasion. I actually try to avoid using maybeAuthId at all in my code. The problem is that there are definitely some use cases where maybeAuth isn't a possibility, such as when the user information is not stored in Persistent. Perhaps our solution should be to document this behavior and simply not export maybeAuthId from the standard modules or in the scaffolding.

@meteficha
Copy link
Member Author

The problem I've run into was due to a use of maybeAuthId on yesod-auth-fb, so you'd recommend me to change it into a maybeAuth even though I won't use that information at all?

@meteficha
Copy link
Member Author

If we could cache the result of maybeAuth on the request-local storage it would become cheap to implement maybeAuthId = fmap entityKey <$> maybeAuth. And the cache would be beneficial anyway. Finally, it seems that the current CacheKey suffices to implement this feature.

@snoyberg
Copy link
Member

That's a good idea. I'd actually like to implement #268 for the 1.2 release. So let's approach this by implementing the caching behavior for maybeAuth right now using the current infrastructure and then upgrading to the new approach in the 1.2 branch. This can work as a proving case that we've implemented the feature properly.

@meteficha
Copy link
Member Author

Now that #268 is solved it should be fairly easy to solve this issue.

@snoyberg
Copy link
Member

Good point; I've refactored slightly to make this work. Can you review my commit in b5a1d76?

@meteficha
Copy link
Member Author

Looks good, there are just a few places that I think you've used the wrong function.

snoyberg added a commit that referenced this issue Mar 24, 2013
@snoyberg
Copy link
Member

It wasn't by mistake: maybeAuthId makes more requirements than maybeAuthIdRaw does. I was playing around with the idea of using DefaultSignatures to solve the problem, and eventually got it working in 7748a19.

@meteficha
Copy link
Member Author

Ok, now I see it. I'd just like to see a big fat warning on cachedAuth stating that it must not be called with different arguments on the same request.

@snoyberg
Copy link
Member

I don't mind adding the warning, but neither cachedAuth nor CachedMaybeAuth is exported, which makes it impossible for users to accidentally mess things up. The only way to have a problem is if Yesod.Auth itself had a bug.

@gregwebs
Copy link
Member

gregwebs commented Apr 5, 2013

Should this ticket be closed?

@snoyberg
Copy link
Member

snoyberg commented Apr 7, 2013

Yes, thanks.

@snoyberg snoyberg closed this as completed Apr 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants