AscendingCreations / AxumSession

Axum Session Management Libraries that use Sqlx
MIT License
142 stars 29 forks source link

The demo in the README gives a HTTP 401 Unauthorized error #10

Closed jmoore34 closed 2 years ago

jmoore34 commented 2 years ago

I created a bare-bones repo jmoore34/axum-session-test to test the non-persistent example given in the README. When starting the server and navigating to the route 127.0.0.1:3000/greet/jon, I get a 401 Unauthorized error in the browser.

image

(Note: I initially noticed this error in a larger project that used this library, so I created this bare-bones repo to try to help isolate the issue.)

genusistimelord commented 2 years ago

Thank you for reporting this. I will look into what the cause is.

genusistimelord commented 2 years ago

Ahh so the fix for this issue is to create the Cookie manager After the Session due to the order it gets invoked by axum.

// build our application with some routes
    let app = Router::new()
        .route("/greet", get(greet))
        .layer(axum_session_runner!(session_store))
        .layer(tower_cookies::CookieManagerLayer::new()); //this gets loaded first when set after due to the Onion layer ordering or axum.
genusistimelord commented 2 years ago

I will also will look into just handling the Cookie manager creation internally.