feat(auth): implement user registration and login with JWT authentication
- 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.
This commit is contained in:
@@ -49,3 +49,22 @@ pub async fn make_delete_request(app: Router, url: &str, user_id: Option<i32>) -
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn make_jwt_request(
|
||||
app: Router,
|
||||
url: &str,
|
||||
method: &str,
|
||||
body: Option<String>,
|
||||
token: &str,
|
||||
) -> Response {
|
||||
let builder = Request::builder()
|
||||
.method(method)
|
||||
.uri(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", format!("Bearer {}", token));
|
||||
|
||||
let request_body = body.unwrap_or_default();
|
||||
app.oneshot(builder.body(Body::from(request_body)).unwrap())
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user