Skip to content

fix(auth): standardize login field to email and fix VITE_API_BASE_URL…#50

Open
latakshsariyapatidar wants to merge 3 commits into
rdodiya:gssoc_developfrom
latakshsariyapatidar:fix/login-email-field-and-vite-env
Open

fix(auth): standardize login field to email and fix VITE_API_BASE_URL…#50
latakshsariyapatidar wants to merge 3 commits into
rdodiya:gssoc_developfrom
latakshsariyapatidar:fix/login-email-field-and-vite-env

Conversation

@latakshsariyapatidar

Copy link
Copy Markdown

What changed?

Fixes two issues in the frontend config and login flow, and aligns the backend to use email as the auth identifier as requested by @rdodiya.

Frontend

  • api.js: Replaced import.meta.env.API_BASE_URL with import.meta.env.VITE_API_BASE_URL so Vite correctly exposes the env variable instead of silently falling back to hardcoded localhost
  • Login.jsx: Standardized Formik initial values, input field bindings, and validation error rendering from usernameemail. Added email format validation.

Backend

  • LoginRequest.java: Renamed username field to email, added @Email validation
  • AuthServiceImpl.java: Updated authentication logic to look up users by email
  • AuthResponse.java: Updated response payload to return email field

Type

  • New feature
  • Bug fix
  • Documentation

Testing

Tested locally — login form shows correct email validation errors, API calls hit the correct base URL, and backend authentication works with email as identifier.

Related Issue

Closes #28

Additional Notes

Changes are backward-compatible. The email field replaces username across the full auth flow as per maintainer's guidance.

@latakshsariyapatidar

Copy link
Copy Markdown
Author

Hi @rdodiya,

I've pushed the additional changes to this PR:

  • Updated CustomUserDetailsService.java to fix the hardcoded default username/password issue
  • Tested the full login flow — login works correctly with the default credentials.

Please review when you get a chance. Happy to make further adjustments if needed! 🙏

@rdodiya

rdodiya commented May 13, 2026

Copy link
Copy Markdown
Owner

Hi @latakshsariyapatidar ,
Please resolve conflicts.

@Karanjot786

Copy link
Copy Markdown

Hey @latakshsariyapatidar! Saw your work on GSSoC 2026.

We are building TermUI, a TypeScript terminal UI framework with React-style hooks and JSX, rendered entirely in the terminal.

We have 67 unassigned GSSoC issues open. 19 are marked good first issue. Your JavaScript background transfers directly.

Karanjot, TermUI maintainer

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to (1) fix frontend API base-URL configuration for Vite by using VITE_API_BASE_URL, and (2) standardize authentication to use email as the identifier across frontend and backend.

Changes:

  • Frontend: updated Axios base URL to read from import.meta.env.VITE_API_BASE_URL (with localhost fallback).
  • Backend: migrated auth DTOs/services to use email instead of username in login/refresh responses and request payloads.
  • Backend: introduced a startup DataInitializer to seed roles/users.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
RestroHub/src/main/java/com/restroly/qrmenu/security/CustomUserDetailsService.java Adjusts user lookup semantics for auth, but currently introduces a compilation error (duplicate field).
RestroHub/src/main/java/com/restroly/qrmenu/config/DataInitializer.java Adds startup seeding of default roles/users (needs profile-gating to avoid production security risk).
RestroHub/src/main/java/com/restroly/qrmenu/auth/service/AuthServiceImpl.java Updates login/refresh flows to use email, but leaves inconsistent credential error messaging.
RestroHub/src/main/java/com/restroly/qrmenu/auth/dto/LoginRequest.java Renames login identifier to email and adds email validation (API-breaking unless migrated/versioned).
RestroHub/src/main/java/com/restroly/qrmenu/auth/dto/AuthResponse.java Renames response field to email (API-breaking) and currently leaves other code constructing .username(...).
RestroHub/src/main/java/com/restroly/qrmenu/auth/controller/AuthController.java Updates OpenAPI examples/logging to use email (docs can diverge from runtime error message until handler is updated).
RestroHub-FrontEnd/src/services/public/ApiService.js Uses VITE_API_BASE_URL for API calls with a localhost fallback.
RestroHub-FrontEnd/src/services/common/api.js Simplifies Axios baseURL assignment using VITE_API_BASE_URL.
RestroHub-FrontEnd/src/pages/public/Login.jsx Partially updates UI messaging, but still submits username to the backend and has a styling/validation binding bug.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to +25
private final UserRepository userRepository;
private final com.restroly.qrmenu.user.repository.UserRepository userRepository;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latakshsariyapatidar remove 1 userRepository as it is declared twice

Comment on lines +9 to +20
import org.springframework.boot.CommandLineRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Component
@RequiredArgsConstructor
@Slf4j
public class DataInitializer implements CommandLineRunner {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latakshsariyapatidar Delete DataInitializer class as it is not required.

Comment on lines +31 to +32
@Schema(description = "Email of authenticated user", example = "admin@restroly.com")
private String email;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latakshsariyapatidar changes username to emails in other classes

} catch (BadCredentialsException ex) {
log.warn("Failed login attempt for user: {}", loginRequest.getUsername());
log.warn("Failed login attempt for user: {}", loginRequest.getEmail());
throw new BadCredentialsException("Invalid username or password");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latakshsariyapatidar Change this

Comment on lines 326 to +330
placeholder="Enter email or username"
value={formik.values.username}
onChange={formik.handleChange}
onBlur={formik.handleBlur}
className={inputClass("username")}
className={inputClass("email")}
Comment on lines 187 to 190
} catch (err) {
toast.error(
err.response?.data?.message || "Invalid username or password"
err.response?.data?.message || "Invalid email or password"
);
Comment on lines 107 to 111
{
"status": 401,
"error": "UNAUTHORIZED",
"message": "Invalid username or password",
"message": "Invalid email or password",
"path": "/api/v1/auth/login",
Comment on lines +31 to +32
@Schema(description = "Email of authenticated user", example = "admin@restroly.com")
private String email;
Comment on lines +15 to +18
@NotBlank(message = "Email is required")
@jakarta.validation.constraints.Email(message = "Invalid email format")
@Schema(description = "Email", example = "admin@restroly.com", requiredMode = Schema.RequiredMode.REQUIRED)
private String email;
@rdodiya

rdodiya commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Hi @latakshsariyapatidar ,
Please review all the co-pilot suggestions and perform necessary code changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Vite API base URL env variable and login form field mismatch

4 participants