Comments (6)
but one can only use async_std
Can you go into more detail here?
We also have an example which may be helpful.
from axum-login.
with jbr version of async_sqlx_session, it's not possible to use tokio runtime, only async_std runtime. Axum uses tokio.
If you create a PgPool with the current version of Sqlx (0.6), you get the following error when you use from client(pool) in CyrusAlbright/async_sqlx_session : 'expected sqlx_core::postgres::PgPool, found PgPool'
e.g. :
pub(crate) async fn new_axum_sqlx_session(pool: PgPool) -> SessionLayer {
let store = PostgresSessionStore::from_client(pool); // error is here
store.migrate().await.expect("Couldn't migrate session store");
let secret = rand::thread_rng().gen::<[u8; 128]>();
let session_layer = SessionLayer::new(store, &secret).with_secure(true);
session_layer
}
from axum-login.
Have you looked at the axum-sessions
example? You can disable async-std
(it's only required for the task cleanup) when listing async-sqlx-session
and then provide the Tokio runtime in your project instead.
from axum-login.
Thanks for your advice.
One crate still seems to be compiling an older version of sqlx (5.13). I tried to use PostgresSessionStore with the new(...) function which creates a new connection instead of using the from_client(...) function which uses a pre-existing PgPool and it worked.
The problem is solved but with a non totaly satisfying solution ...
Do you intend to create an axum-signup crate or an axum-auth crate that would unite axum-login and an axum-signup in one crate ?
from axum-login.
I tried to use PostgresSessionStore with the new(...) function which creates a new connection instead of using the from_client(...)
Hmm. Okay, that doesn't sound like something is working the way we'd want. You should be able to reuse a pool. Are you able to share an example we could debug?
Do you intend to create an axum-signup crate or an axum-auth crate that would unite axum-login and an axum-signup in one crate ?
I'm not familiar with the signup crate, but if it's compatible, that sounds like a promising direction. :)
from axum-login.
Here's a diff you can try if you like, it should allow you to use a pool.
diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml
index f57d65d..e3d1097 100644
--- a/examples/sqlite/Cargo.toml
+++ b/examples/sqlite/Cargo.toml
@@ -5,7 +5,13 @@ edition = "2021"
publish = false
[dependencies]
-axum = "0.5.13"
+axum = "0.5"
+
+[dependencies.async-sqlx-session]
+git = "https://github.com/maxcountryman/async-sqlx-session.git"
+rev = "08754e6388a64e88a69fa8f8b8c537448e23f249"
+default-features = false
+features = ["sqlite", "tokio_rustls"]
[dependencies.axum-login]
path = "../../"
@@ -16,7 +22,7 @@ version = "0.8.5"
features = ["min_const_gen"]
[dependencies.sqlx]
-version = "0.6.1"
+version = "0.6"
default-features = false
features = ["runtime-tokio-rustls", "sqlite"]
diff --git a/examples/sqlite/src/main.rs b/examples/sqlite/src/main.rs
index 3968298..fa7ffb7 100644
--- a/examples/sqlite/src/main.rs
+++ b/examples/sqlite/src/main.rs
@@ -4,10 +4,10 @@
//! cd examples && cargo run -p example-sqlite
//! ```
+use async_sqlx_session::SqliteSessionStore;
use axum::{response::IntoResponse, routing::get, Extension, Router};
use axum_login::{
- axum_sessions::{async_session::MemoryStore, SessionLayer},
- AuthLayer, AuthUser, RequireAuthorizationLayer, SqliteStore,
+ axum_sessions::SessionLayer, AuthLayer, AuthUser, RequireAuthorizationLayer, SqliteStore,
};
use rand::Rng;
use sqlx::sqlite::SqlitePoolOptions;
@@ -35,7 +35,15 @@ type AuthContext = axum_login::extractors::AuthContext<User, SqliteStore<User>>;
async fn main() {
let secret = rand::thread_rng().gen::<[u8; 64]>();
- let session_store = MemoryStore::new();
+ let pool = sqlx::SqlitePool::connect("sqlite::memory:").await.unwrap();
+ let session_store = SqliteSessionStore::from_client(pool);
+ //let session_store = SqliteSessionStore::new("sqlite::memory:")
+ // .await
+ // .expect("Could not connect to SQLite.");
+ session_store
+ .migrate()
+ .await
+ .expect("Could not migrate session store.");
let session_layer = SessionLayer::new(session_store, &secret).with_secure(false);
let pool = SqlitePoolOptions::new()
diff --git a/examples/sqlite/user_store.db b/examples/sqlite/user_store.db
index d26f080..0c3a45c 100644
Binary files a/examples/sqlite/user_store.db and b/examples/sqlite/user_store.db differ
Unfortunately the async-sqlx-session
crate needs to be updated to work with [email protected]
it seems. (There's an open PR from just over a year ago.)
Similarly there's a Redis variant which is not compatible with Tokio. I've reached out to the author offering support but they haven't responded so perhaps the best way forward is to maintain separate forks.
from axum-login.
Related Issues (20)
- Support tower-sessions HOT 3
- Feature Request: Locking user out HOT 2
- Consider reorganizing examples into a workspace
- Make the `DATA_KEY` configurable
- Evaluate better management of sensitive data HOT 1
- Bring coverage back HOT 2
- Macro hygiene is broken
- Error type made public HOT 5
- Custom `Debug` implementation for `User` but not `Credentials` in SQLite example? HOT 1
- Could not find `http` in `$crate` HOT 1
- Is 2FA possible?
- `AuthnBackend#Credentials: Clone` breaks `oauth2::PkceCodeVerifier` HOT 1
- Session Cookie Removed on Reload
- Can't extract auth session. Is `AuthManagerLayer` enabled? HOT 8
- login_required macro generates invalid redirect URL HOT 3
- State isn't saved when using axum-login with leptos
- Going back to login page should not complete if the user logged HOT 2
- Dependency on time crate in "Duration"
- Session expiration has no effect
- examples/sqlite database in wrong folder and useless files HOT 2
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 axum-login.