-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Support MongoDBStore #5
Conversation
Wonderful! Thank you for this. |
It looks like we'll want to run cargo +nightly fmt to pass CI. |
We're getting closer--it looks like the integration tests might not be passing. |
Yeah, I'm investigating why it does not work, it's been 1hr but still no progress |
Does it work for you locally? I'm not too familiar with Mongo unfortunately, but I wonder if there could be some difference between the container's version of Mongo and a local version. |
Unfortunately, it doesn't work locally. My guess is that Deserializing Object from MongoDB to Rust SessionRecord maybe the cause |
I'm not sure exactly how you're testing, but if you're using the So something like this: [tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let database_url = std::option_env!("DATABASE_URL").expect("Missing DATABASE_URL.");
let client = mongodb::Client::with_uri_str(database_url).await.unwrap();
let session_store = MongoDBStore::new(client, "tower-sessions".to_string());
let session_service = ServiceBuilder::new()
.layer(HandleErrorLayer::new(|err: BoxError| async {
dbg!(err);
StatusCode::BAD_REQUEST
}))
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_max_age(Duration::seconds(10)),
);
let app = Router::new()
.route("/", get(handler))
.layer(session_service);
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await?;
Ok(())
} |
# Conflicts: # .github/workflows/rust.yml # src/lib.rs
Tests passed on local |
self.col() | ||
.update_one( | ||
doc! { | ||
"_id": session_record.id().as_uuid() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being able to use the native type seems quite nice! This seems good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I noticed that sqlx providers don't use native uuid (binary), or maybe it needs to be stored as string? I'm not familiar with uuid in sql.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least with Postgres, there's a module you can enable to support UUID as a column type. But I'm not sure if it's available by default these days and so it's not something that's currently being used.
Codecov Report
@@ Coverage Diff @@
## main #5 +/- ##
==========================================
+ Coverage 58.09% 58.41% +0.31%
==========================================
Files 7 7
Lines 210 214 +4
==========================================
+ Hits 122 125 +3
- Misses 88 89 +1
|
This PR adds MongoDB as an option for storing sessions.
closes #4