Giter Club home page Giter Club logo

Comments (5)

jbr avatar jbr commented on July 18, 2024

Can you provide more context for this question? What framework are you using?

from async-redis-session.

AppyCat avatar AppyCat commented on July 18, 2024

Yes, I am using Axum web framework.

I'm trying to use encrypted session cookies stored in Redis.

I read the docs, but don't see a way to add the Redis connection as a layer in Axum. I do see how to add the session as a session_layer.

The use case is to store a users id in an encrypted cookie with Redis as the session store.

Currently a record inserted in Redis in one handler cannot be retrieved in another handler.

Here's my setup:

use axum_sessions::{async_session::{Session, SessionStore as _}, SameSite, SessionLayer};
use async_redis_session::RedisSessionStore;

let secret = b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
let session_layer = SessionLayer::new(store.unwrap(), secret)
.with_cookie_name("test-cookie")
.with_cookie_path("/")
.with_cookie_domain("www.test-cookie.com")
.with_same_site_policy(SameSite::None)
.with_session_ttl(Some(Duration::from_secs(60 * 5)))
.with_save_unchanged(true)
.with_secure(false);

from async-redis-session.

jbr avatar jbr commented on July 18, 2024

I think this is an issue for the Axum sessions library, if I understand correctly

from async-redis-session.

AppyCat avatar AppyCat commented on July 18, 2024

Thanks, I put a note out to them.

However am also getting the following errors on methods not existing in store from async-redis-session:

92 | let cookie_value = store.store_session(session).await;
| ^^^^^^^^^^^^^ method not found in Result<RedisSessionStore, redis::types::RedisError>

error[E0599]: no method named load_session found for enum Result in the current scope
--> src/main.rs:93:29
|
93 | let mut session = store.load_session("test-cookie".parse().unwrap()).await.unwrap();
| ^^^^^^^^^^^^ method not found in Result<RedisSessionStore, redis::types::RedisError>

Code is:

async fn do_something(Extension(session): Extension<Session>) -> Json<Value> {
    let store = RedisSessionStore::new("redis://127.0.0.1/");
    let cookie_value = store.store_session(session).await;
    let mut session = store.load_session("test-cookie".parse().unwrap()).await.unwrap();

    let user_id: String = session.get::<String>("user_id").unwrap();
    Json(json!({ "data": user_id }))
}

from async-redis-session.

jbr avatar jbr commented on July 18, 2024

store is a Result that needs to be unwrapped or the error needs to be handled. Regardless, this is an issue for the axum session library.

from async-redis-session.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.