Updated user authentication system

This commit is contained in:
2025-03-12 22:27:35 +01:00
parent 8e1e37dbb2
commit c07e5b5ceb
2 changed files with 143 additions and 20 deletions

View File

@@ -1,24 +1,34 @@
mod users;
use std::sync::Mutex;
use users::*;
use actix_web::{App, HttpServer};
use actix_web::web::Data;
use actix_web::{App, HttpServer};
use sqlx::sqlite::SqlitePool;
#[derive(Clone)]
struct AppState {
database: SqlitePool,
token_expiration: u64,
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let pool = SqlitePool::connect("sqlite:database.db").await.expect("Could not connect to db");
let app_state = Data::new(AppState { database: pool });
let pool = SqlitePool::connect("sqlite:database.db")
.await
.expect("Could not connect to db");
let app_state = Data::new(AppState {
database: pool,
token_expiration: 86400,
});
HttpServer::new(move || {
App::new()
.service(login)
.service(register)
.service(logout)
.app_data(app_state.clone())
}).bind(("127.0.0.1", 8000))?.run().await
})
.bind(("127.0.0.1", 8000))?
.run()
.await
}