diff --git a/.env.example b/.env.example index 7b1715c..94d5527 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,11 @@ PORT=8000 FRONTEND_URL=http://localhost:3000 API_URL=http://localhost:8000 +# Google OAuth (optional; required only for "Sign in with Google") +GOOGLE_CLIENT_ID= +GOOGLE_CLIENT_SECRET= +GOOGLE_REDIRECT_URL=http://localhost:8000/api/v1/auth/google/callback + # Frontend NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1 diff --git a/backend/api/src/api/handlers/auth_handler.rs b/backend/api/src/api/handlers/auth_handler.rs index 1fb7e65..e9f4ad1 100644 --- a/backend/api/src/api/handlers/auth_handler.rs +++ b/backend/api/src/api/handlers/auth_handler.rs @@ -203,6 +203,11 @@ pub struct OAuthCallbackQuery { pub async fn google_login() -> Result { let client_id = std::env::var("GOOGLE_CLIENT_ID").unwrap_or_default(); + if client_id.trim().is_empty() { + return Err(AppError::BadRequest( + "Google OAuth is not configured. Set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET.".into(), + )); + } let redirect_uri = std::env::var("GOOGLE_REDIRECT_URL") .unwrap_or_else(|_| "http://localhost:8000/api/v1/auth/google/callback".to_string()); @@ -219,6 +224,11 @@ pub async fn google_callback( ) -> Result { let client_id = std::env::var("GOOGLE_CLIENT_ID").unwrap_or_default(); let client_secret = std::env::var("GOOGLE_CLIENT_SECRET").unwrap_or_default(); + if client_id.trim().is_empty() || client_secret.trim().is_empty() { + return Err(AppError::BadRequest( + "Google OAuth is not configured. Set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET.".into(), + )); + } let redirect_uri = std::env::var("GOOGLE_REDIRECT_URL") .unwrap_or_else(|_| "http://localhost:8000/api/v1/auth/google/callback".to_string()); let frontend_url =