axum-login
axum-login copied to clipboard
Postgres example
I'm working on adding an example for postgres, since it seems to differ a bit from the sqlite example provided. I'm currently debugging why the session authentication here:
// todo: currently returning Err
let user = match auth_session.authenticate(creds.clone()).await {
Ok(Some(user)) => user,
Ok(None) => {
messages.error("Invalid credentials");
let mut login_url = "/login".to_string();
if let Some(next) = creds.next {
login_url = format!("{}?next={}", login_url, next);
};
return Redirect::to(&login_url).into_response();
}
Err(_) => return StatusCode::INTERNAL_SERVER_ERROR.into_response(),
};
is failing. Marking as draft PR.
I wrote this postgres example to document a bug I'm running into in my own repo. This PR creates an example for postgres
, and documents a failing assumption--that a table called session
exists in the database.
The following login method fails accordingly:
pub async fn login(
mut auth_session: AuthSession,
messages: Messages,
Form(creds): Form<Credentials>,
) -> impl IntoResponse {
// todo: see auth session:
// auth session thinks a table called "session" exists:
// schema_name: "tower_sessions",
// table_name: "session",
#[cfg(test)]
dbg!(auth_session.clone());
let user = match auth_session.authenticate(creds.clone()).await {
This is either a bug in axum-login
, or I may otherwise misunderstand how the login function should accordingly be changed from the sqlite
example.
with the last 3 commits, I've updated the postgres example to pass unit tests.
@thor314 is there any news?
This should probably be an independent repository, perhaps even a fully-fledged template others could build from. I don't think it's prudent to increase the maintenance burden of axum-login
itself so I'm going to close this. If you end up establishing a template repo, please feel free to link to it from the axum-login
README.