Closed Th3Whit3Wolf closed 4 years ago
Also should this be placed in Actix's issues as well? I noticed in their Actix Identity Documentation they have a remarkably similar example.
use actix_web::*;
use actix_identity::{Identity, CookieIdentityPolicy, IdentityService};
async fn index(id: Identity) -> String {
// access request identity
if let Some(id) = id.identity() {
format!("Welcome! {}", id)
} else {
"Welcome Anonymous!".to_owned()
}
}
async fn login(id: Identity) -> HttpResponse {
id.remember("User1".to_owned()); // <- remember identity
HttpResponse::Ok().finish()
}
async fn logout(id: Identity) -> HttpResponse {
id.forget(); // <- remove identity
HttpResponse::Ok().finish()
}
fn main() {
let app = App::new().wrap(IdentityService::new(
// <- create identity middleware
CookieIdentityPolicy::new(&[0; 32]) // <- create cookie identity policy
.name("auth-cookie")
.secure(false)))
.service(web::resource("/index.html").to(index))
.service(web::resource("/login.html").to(login))
.service(web::resource("/logout.html").to(logout));
}
Are you still seeing this issue? If so, please can you provide steps to reproduce it. I've just tested it both in httpie and in Chrome (changing /login
to a GET route) and both work as expected.
Everything works fine. I can verify via curl. I was expecting to see it in html since id is being passed around but I guess it doesn't work like that.
Look at these lines . . .
https://github.com/actix/examples/blob/998f92d2e3d524366531a1acb19204420f6eed58/cookie-auth/src/main.rs#L5-L42
I would expect when going from
127.0.0.1:8080
to127.0.0.1:8080/login
and then back to127.0.0.1:8080
to arrive at a webpage sayingHello user1
What you actually get is
Hello Anonymous!