- Added `bcrypt`, `jsonwebtoken`, and `once_cell` dependencies to manage password hashing and JWT handling. - Created `Claims` struct for JWT claims and implemented token generation in the login route. - Implemented user registration and authentication logic in the `auth` module. - Updated error handling to include validation errors. - Created new routes for user registration and login, and integrated them into the main router. - Added tests for the authentication flow, including registration and login scenarios. - Updated user model to include a password hash field. - Refactored user creation logic to include password validation. - Adjusted feed and user routes to utilize JWT for authentication.
27 lines
832 B
Rust
27 lines
832 B
Rust
pub struct Config {
|
|
pub db_url: String,
|
|
pub host: String,
|
|
pub port: u32,
|
|
pub prefork: bool,
|
|
pub auth_secret: String,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_env() -> Config {
|
|
Config {
|
|
db_url: std::env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file"),
|
|
host: std::env::var("HOST").expect("HOST is not set in .env file"),
|
|
port: std::env::var("PORT")
|
|
.expect("PORT is not set in .env file")
|
|
.parse()
|
|
.expect("PORT is not a number"),
|
|
prefork: std::env::var("PREFORK").is_ok_and(|v| v == "1"),
|
|
auth_secret: std::env::var("AUTH_SECRET").unwrap_or_else(|_| "secret".into()),
|
|
}
|
|
}
|
|
|
|
pub fn get_server_url(&self) -> String {
|
|
format!("{}:{}", self.host, self.port)
|
|
}
|
|
}
|