api/routes/auth/mod.rs
1//! # auth Routes Module
2//!
3//! This module defines and wires up routes for the `/auth` endpoint group.
4//!
5//! ## Structure
6//! - `post.rs` — POST handlers (e.g., register)
7//! - `get.rs` — GET handlers (e.g., current user info)
8//!
9//! ## Usage
10//! The `auth_routes()` function returns a `Router` which is nested under `/auth` in the main application.
11
12use axum::{middleware::from_fn, Router, routing::{get, post}};
13use crate::auth::guards::require_authenticated;
14use post::{
15 register, login, request_password_reset, verify_reset_token,
16 reset_password, upload_profile_picture, change_password
17};
18use get::{get_me, get_avatar, has_role_in_module, get_module_role};
19use util::state::AppState;
20
21pub mod post;
22pub mod get;
23
24// # Auth Routes Module
25//
26// This module defines and wires up routes under the `/api/auth` endpoint group.
27//
28// ## Structure
29// - `post.rs` — POST handlers for authentication actions like registration, login, and password reset.
30// - `get.rs` — GET handlers for retrieving authenticated user info, avatars, and role checks.
31//
32// ## Routes
33// - `POST /auth/register` — Register a new user.
34// - `POST /auth/login` — Authenticate an existing user.
35// - `POST /auth/request-password-reset` — Initiate password reset process.
36// - `POST /auth/verify-reset-token` — Validate a password reset token.
37// - `POST /auth/reset-password` — Complete password reset.
38// - `POST /auth/upload-profile-picture` — Upload a user profile picture.
39// - `GET /auth/me` — Retrieve info about the currently authenticated user.
40// - `GET /auth/avatar/{user_id}` — Retrieve a user's profile picture.
41// - `GET /auth/has-role` — Check if the current user has a role in a module.
42// -
43//
44// ## Usage
45// Use the `auth_routes()` function to mount all `/auth` endpoints under the main application router.
46
47pub fn auth_routes() -> Router<AppState> {
48 Router::new()
49 .route("/register", post(register))
50 .route("/login", post(login))
51 .route("/request-password-reset", post(request_password_reset))
52 .route("/verify-reset-token", post(verify_reset_token))
53 .route("/reset-password", post(reset_password))
54 .route("/me", get(get_me))
55 .route("/upload-profile-picture", post(upload_profile_picture))
56 .route("/avatar/{user_id}", get(get_avatar))
57 .route("/has-role", get(has_role_in_module))
58 .route("/module-role", get(get_module_role))
59 .route("/change-password", post(change_password).route_layer(from_fn(require_authenticated)))
60}