Skip to content

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions