Skip to content

fix: JWT field name mismatch in register + stuck 'Adding...' button in TableCheckoutModal #31

Closed

Description

@khaira777

Bug 1: JWT field name mismatch breaks registration flow

Location: frontend/src/store/auth.ts:47-55

The backend POST /auth/register returns access_token, but the frontend register function reads data.token (which is undefined).

Backend (main/routes/auth.ts:455-456):

res.json({ access_token: token, ... });

Frontend (frontend/src/store/auth.ts:47-55):

register: async (registerData: RegisterData) => {
  const { data } = await api.post('/auth/register', registerData);
  localStorage.setItem('token', data.token);  // ❌ should be data.access_token
  set({
    user: data.user,
    token: data.token,  // ❌ undefined
    tenants: [data.tenant],
  });
},

Impact: After registration, the token stored is undefined. Subsequent API calls fail with 401. User appears logged in but sessions are broken until re-login.

Fix: Change data.token to data.access_token (matching the login function on line 39 and the backend response).


Bug 2: setAddingItems(true) never reset in TableCheckoutModal

Location: frontend/src/components/pos/TableCheckoutModal.tsx:71-75

const handleAddCartToOrder = async () => {
  if (!order || !onAddCartToOrder) return;
  setAddingItems(true);           // ← set to true
  onAddCartToOrder(table, order);  // ← never reset
};

Compare with handleCheckout which has proper try/finally:

const handleCheckout = async () => {
  setGenerating(true);
  try { ... } finally { setGenerating(false); }
};

Impact: Button can get stuck in "Adding..." state if the callback throws or the modal stays open. Low severity but inconsistent with the rest of the component.

Fix: Add try/finally around the callback, or accept that the parent handles state and reset in a finally block.

Activity

  1. added a commit that references this issue on Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions