Comments (5)
Can you provide more context for this question? What framework are you using?
from async-redis-session.
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.
I think this is an issue for the Axum sessions library, if I understand correctly
from async-redis-session.
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.
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)
- Dynamic session key prefixes HOT 3
- Tide support? HOT 1
- sliding expiration support
- Check health of connection to Redis HOT 2
- Support for tokio-native-tls-comp? HOT 6
- Maintenance status? HOT 12
- Warning is displayed when building
- RedisSessionStore::from_client wouldn't worked for new redis-rs versions.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-redis-session.