Updated user authentication system
This commit is contained in:
20
src/main.rs
20
src/main.rs
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user