Skip to content

Commit 7ede1cd

Browse files
committed
cleanup + tiny fixes
1 parent 128231f commit 7ede1cd

File tree

9 files changed

+28
-40
lines changed

9 files changed

+28
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ When using a WakaTime client, point your requests to `http://localhost:3000/api/
7878

7979
## License
8080

81-
This project is licensed under the [GNU AGPLv3](./LICENSE)
81+
This project is licensed under the [GNU AGPLv3](https://github.com/ImShyMike/rustytime/blob/HEAD/LICENSE)

frontend/src/lib/utils/serverApi.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class ServerApiClient {
3030

3131
// Forward cookies from the incoming request
3232
const cookieHeader = event.request.headers.get('cookie');
33-
console.error('Requesting', url, 'with cookies:', cookieHeader);
3433

3534
const config: RequestInit = {
3635
credentials: 'include',

frontend/src/routes/admin/+page.server.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export const load: PageServerLoad = async (event) => {
99
const adminData = await serverApi.get<AdminResponse>('/page/admin', event);
1010

1111
if (adminData && adminData.auth_url) {
12-
console.error('Unauthorized access to admin, redirecting to home.');
13-
console.error(adminData);
1412
throw redirect(302, '/?auth_error=unauthorized');
1513
}
1614

frontend/src/routes/dashboard/+page.server.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export const load: PageServerLoad = async (event) => {
99
const dashboardData = await serverApi.get<DashboardResponse>('/page/dashboard', event);
1010

1111
if (dashboardData && dashboardData.auth_url) {
12-
console.error('Unauthorized access to dashboard, redirecting to home.');
13-
console.error(dashboardData);
1412
throw redirect(302, '/?auth_error=unauthorized');
1513
}
1614

rustytime/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustytime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rustytime-server"
33
description = "🕒 blazingly fast time tracking for developers"
4-
version = "0.4.2"
4+
version = "0.4.3"
55
edition = "2024"
66
authors = ["ImShyMike"]
77
readme = "../README.md"

rustytime/src/handlers/homepage.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::models::user::User;
22
use crate::state::AppState;
3-
use axum::{Extension, Json, extract::State, response::Response};
3+
use axum::{extract::State, response::Redirect};
44
use serde::Serialize;
55

66
#[derive(Serialize)]
@@ -12,14 +12,7 @@ pub struct HomePageResponse {
1212
/// Handler for the homepage
1313
pub async fn home_page(
1414
State(_app_state): State<AppState>,
15-
user: Option<Extension<User>>,
16-
) -> Result<Json<HomePageResponse>, Response> {
17-
// check if user is authenticated
18-
let is_authenticated = user.is_some();
19-
let user = user.map(|ext| ext.0);
20-
21-
Ok(Json(HomePageResponse {
22-
is_authenticated,
23-
user,
24-
}))
15+
) -> Result<Redirect, Redirect> {
16+
let frontend_url = std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string());
17+
Ok(Redirect::to(&frontend_url))
2518
}

rustytime/src/routes/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn create_app_router(app_state: AppState) -> Router {
2020
// required authentication
2121
.merge(protected_routes(app_state.clone()))
2222
// optional authentication
23-
.merge(semi_protected_routes(app_state.clone()))
23+
// .merge(semi_protected_routes(app_state.clone()))
2424
// admin routes
2525
.merge(create_admin_routes(app_state.clone()))
2626
// API routes
@@ -44,6 +44,7 @@ async fn not_found() -> impl IntoResponse {
4444
/// Public routes that don't require authentication
4545
fn public_routes() -> Router<AppState> {
4646
Router::new()
47+
.route("/", get(home_page))
4748
}
4849

4950
/// Protected routes that require authentication
@@ -57,14 +58,13 @@ fn protected_routes(app_state: AppState) -> Router<AppState> {
5758
}
5859

5960
/// Routes that work with and without authentication
60-
fn semi_protected_routes(app_state: AppState) -> Router<AppState> {
61-
Router::new()
62-
.route("/", get(home_page))
63-
.layer(axum_middleware::from_fn_with_state(
64-
app_state,
65-
middleware::optional_auth,
66-
))
67-
}
61+
// fn semi_protected_routes(app_state: AppState) -> Router<AppState> {
62+
// Router::new()
63+
// .layer(axum_middleware::from_fn_with_state(
64+
// app_state,
65+
// middleware::optional_auth,
66+
// ))
67+
// }
6868

6969
/// Admin routes that require admin privileges
7070
pub fn create_admin_routes(app_state: AppState) -> Router<AppState> {

rustytime/src/utils/middleware.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ pub async fn require_auth(
2828
}
2929

3030
/// Middleware to inject the user if authenticated
31-
pub async fn optional_auth(
32-
State(app_state): State<AppState>,
33-
cookies: Cookies,
34-
mut request: Request,
35-
next: Next,
36-
) -> Response {
37-
// try to get current user and add to request extensions
38-
if let Ok(Some(user)) = SessionManager::get_current_user(&cookies, &app_state.db_pool).await {
39-
request.extensions_mut().insert(user);
40-
}
31+
// pub async fn optional_auth(
32+
// State(app_state): State<AppState>,
33+
// cookies: Cookies,
34+
// mut request: Request,
35+
// next: Next,
36+
// ) -> Response {
37+
// // try to get current user and add to request extensions
38+
// if let Ok(Some(user)) = SessionManager::get_current_user(&cookies, &app_state.db_pool).await {
39+
// request.extensions_mut().insert(user);
40+
// }
4141

42-
next.run(request).await
43-
}
42+
// next.run(request).await
43+
// }
4444

4545
/// Middleware to require admin privileges
4646
pub async fn require_admin(

0 commit comments

Comments
 (0)