-
Notifications
You must be signed in to change notification settings - Fork 14
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
Access session in BeforeMiddleware panics #6
Labels
Comments
Since |
Maybe I'm not understanding what's going on, but I'm getting the same thing I believe. Could you clearify the answer above? Here's some of my implementation:
|
I understand that the provided examples are quite poor, or the API is. The
problem is that you need to wrap the authentication middleware around the
entire chain, like this:
```
chain = ...
chain.link_before(Authentication);
chain = SessionStorage.new(..).around(Box::new(chain));
Iron.new(chain)...
```
Either the examples need to be fixed or the API adjusted... Patches welcome. I
myself don't really use this software much today unfortunately.
…On Wed, Nov 01, 2017 at 09:36:09PM +0000, aetsoftware wrote:
Maybe I'm not understanding what's going on, but I'm getting the same thing I believe. Could you clearify the answer above? Here's some of my implementation:
pub struct Authentication;
impl typemap::Key for Authentication { type Value = u64; }
impl BeforeMiddleware for Authentication {
fn before(&self, req: &mut Request) -> IronResult<()> {
let session = req.session(); ///Panics here
if let Some(session) = try!(session.get::<Login>()) {
let sess: String = session.into_raw();
//Continue
}
Ok(())
}
}
//Usage in main:
let mut chain = Chain::new(router);
chain.link_around(SessionStorage::new(SignedCookieBackend::new(my_secret)));
chain.link_before(Authentication);
Iron::new(chain).http("localhost:3000").unwrap();
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#6 (comment)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I'm trying to access the session in a BeforeMiddleware, in order to check if the request is authenticated. This is my middleware:
This is causing a panic here: https://github.com/iron/iron-sessionstorage/blob/master/src/lib.rs#L131
Is there any way to do what I'm attempting to do, or will I have to move this to the Handlers? I'd rather not put it in the Handlers, since I want to do this for every request, which seems to be pretty much the entire point of BeforeMiddlewares. I suspect that the fact that sessionstorage is an AroundMiddleware makes it impossible to access Sessions in a BeforeMiddleware?
The text was updated successfully, but these errors were encountered: