User authentication prototype

This commit is contained in:
2026-07-14 13:04:11 -04:00
parent fcde51ab3c
commit 82077a2e09
4 changed files with 1066 additions and 36 deletions

View File

@@ -1,13 +1,16 @@
use std::error::Error;
use std::env::var;
use std::error::Error;
use axum::http::{HeaderValue, Method};
use axum::routing::get;
use axum::{serve, Router};
use tokio::net::TcpListener;
use sqlx::postgres::PgPool;
use axum::{Router, serve};
use dotenvy::dotenv;
use sqlx::postgres::PgPool;
use tokio::net::TcpListener;
use tower_http::cors::CorsLayer;
mod users;
use users::{login, me};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
@@ -15,12 +18,20 @@ async fn main() -> Result<(), Box<dyn Error>> {
let db_url = var("DATABASE_URL")?;
let pool = PgPool::connect(&db_url).await?;
let app = Router::new()
.route("/", get(hello))
.route("/status", get(status))
.route("/me", get(me))
.route("/login", get(login))
.layer(
CorsLayer::new()
.allow_origin("http://localhost:5173".parse::<HeaderValue>().unwrap())
.allow_methods([Method::GET])
.allow_credentials(true),
)
.with_state(pool);
let listener = TcpListener::bind("0.0.0.0:80").await?;
let listener = TcpListener::bind("0.0.0.0:8080").await?;
Ok(serve(listener, app).await?)
}
async fn hello() -> &'static str {
"Hello World"
}
async fn status() -> &'static str {
"api online"
}