# Old TIAR UI Behavior Baseline

Source application: `tiar-charging-app`  
Observed source revision: `793c7e8` on branch `dev`  
Observed locally: 2026-08-26

This document records behavior that the new `tiar-webapp` should preserve unless a deliberate migration change is approved.

## Test conditions

- Application started with the old Next.js app in development mode.
- No authenticated user session was used.
- No credentials, OTP, payment data, camera, or location permission was submitted.
- The unauthenticated and public authentication states were verified in the rendered browser UI.
- Authenticated behavior below is marked as source-defined and still needs verification with a dedicated test account.

## Environment behavior

| Behavior | Observation | Migration implication |
|---|---|---|
| Local host normalization | Opening `127.0.0.1:3000` was redirected by the app to an organization-local host such as `parking-plus.localhost:3000`. | Preserve or explicitly redesign organization host resolution before testing route parity. |
| Organization branding | Page title, organization name, logo destination, and branding can change with the resolved organization. | Baseline tests need a fixed organization code and expected branding. |
| Dev tooling | The rendered page showed the Next.js development overlay controls. | Ignore dev overlay elements during visual comparison. |

## Unauthenticated route guard

The following customer routes were requested without a session and redirected to `/signin`:

- `/`
- `/map`
- `/stations`
- `/sessions`
- `/wallet`
- `/profile`
- `/support`
- `/terms-and-conditions`
- `/refund-policies`

The observed sign-in page is therefore the expected entry state for unauthenticated users. The `/set-password` and `/onboarding` routes also redirected to `/signin` without the required authenticated state.

## Public authentication behavior

### `/signin`

- Shows an email-first sign-in flow.
- Offers two continuation choices: `Login with Password` and `Login with OTP`.
- Both login buttons are disabled initially.
- Terms and Conditions must be opened before the agreement checkbox becomes available.
- A Keep me logged in option is present.
- Links to `/signup`.
- Terms modal can be opened and closed.

### `/signup`

- Shows an email-first registration flow.
- Terms agreement is required before `Create account` becomes available.
- Initial `Create account` state is disabled.
- Explains that a verification link is sent by email.
- Links back to `/signin`.

### `/check-email`

- Shows that an email verification link was sent.
- Explains that the link expires and can be requested again from sign-up.
- Provides `Back to Sign Up`.

### `/otp-verify`

- Shows a six-digit verification input.
- `Verify My Account` is disabled until the code is complete.
- Provides a `Resend` action.
- Explains that either the six-digit code or a magic link can complete verification.

### `/verify-email`

- Shows an intermediate `Verifying email` state while the verification token is processed.

### `/forgot-password`

- Shows an email input for account recovery.
- `Send Reset Link` is disabled initially.
- Provides `Back to Sign In`.

### `/reset-password` without a valid token

- Shows an invalid/expired reset-link state.
- Provides `Request New Link` to `/forgot-password`.
- Provides `Back to Sign In`.

## Auth behavior from FE and BE source

The Auth flow was traced through the old frontend and the backend `auth-service` source. The old frontend calls its own Next.js API routes, which then call the backend `/v1.1/*` endpoints.

### Sign-in decision flow

1. The user enters an email. The frontend trims and lowercases it.
2. The user must read/open Terms and Conditions before the acceptance checkbox is enabled.
3. The frontend calls `/api/auth/check-email` before either login path proceeds.
4. An unregistered email can be redirected to `/signup?email=...&reason=unregistered-email` when sign-up is allowed.
5. An existing account can continue with password login or OTP login.
6. If the account has no password, the frontend starts OTP verification and routes to `/otp-verify?reason=password-not-set`.
7. A successful password login routes to `/` when the profile is complete, otherwise `/onboarding`.
8. A backend `428 password not set` response is treated as the OTP/password-setup branch.

### Auth route and response contract

| Old FE route | Backend endpoint | Behavior / expected outcome |
|---|---|---|
| `POST /api/auth/check-email` | `POST /v1.1/check-email` | Returns account existence and whether password/sign-up is available. |
| `POST /api/auth/login-password` | `POST /v1.1/login-password` | Validates organization, user, active status, and bcrypt password; returns user plus access/refresh tokens to the FE server route. |
| `POST /api/auth/request-otp` | `POST /v1.1/request-otp` | Starts the OTP flow for an existing email. |
| `POST /api/auth/verify-otp` | `POST /v1.1/verify-otp` | Verifies the OTP and issues a session or password-setup state. |
| `POST /api/auth/set-password` | `POST /v1.1/set-password` | Sets a required password and rotates/returns the session. |
| `POST /api/auth/change-password` | `POST /v1.1/change-password` | Changes the password for an authenticated user and returns a refreshed session. |
| `POST /api/auth/refresh` | `POST /v1.1/refresh-token` | Rotates a valid refresh token and updates cookies. |
| `POST /api/auth/logout` | `POST /v1.1/logout` | Revokes the refresh token when available; FE clears auth cookies regardless. |
| `GET /api/auth/me` | User-service lookup | Reads the authenticated user and can refresh an expired/missing access token. |
| `POST /api/auth/forgot-password` | `POST /v1.1/request-password-reset` | Requests a password reset link. |
| `POST /api/auth/reset-password` | `POST /v1.1/reset-password` | Completes reset and clears the current auth cookies. |

### Backend login rules

The old `auth-service` requires `email`, `password`, `organization_code`, and `app_name`. It then:

- resolves the organization by code;
- resolves the user using email, organization, and app context;
- rejects inactive users;
- rejects accounts without a password with HTTP `428`;
- compares the supplied password with the stored bcrypt hash;
- issues an access token and opaque refresh token on success.

The old FE supplies the organization and app context server-side, stores tokens in HttpOnly cookies, stores a sanitized user in local storage, and does not expose tokens in the browser JSON response.

### Authenticated session behavior

- Protected customer routes redirect to `/signin` when both access and refresh cookies are absent.
- An expired access token with a valid refresh token is refreshed automatically for page/API requests.
- A failed refresh clears auth cookies and redirects to `/signin`.
- Authenticated users visiting auth pages are redirected to `/`, except users requiring password setup, who are redirected to `/set-password`.
- Logout clears local user state and local storage optimistically, then performs backend logout on a best-effort basis.

### Live verification

The dedicated dev account was used through the old FE login route and returned HTTP `200` with `ok: true`, an active `user` role, `organization_code: SANDBOX`, and `password_setup_required: false`.

## Source-defined authenticated behavior

These behaviors were confirmed from the old route/module structure but require a test account and test data for live browser verification:

| Area | Expected baseline behavior |
|---|---|
| Home | Shows nearest station, news, available stations, recent sessions, and reservation summary. |
| Map/stations | Supports marker/list browsing, station detail navigation, search/filtering, and nearest-station action. |
| Station detail | Shows connectors, rates, live connector status, directions, reservation, and start-charging actions. |
| QR scan | Supports camera scanning and QR image upload. |
| Sessions | Shows session lists/statistics, session detail, live status/cost/energy, stop confirmation, and receipt. |
| Wallet | Shows balance, refresh, transaction history/detail, and top-up entry point. Credit-card management code exists in the repository but is not part of the active old-app behavior baseline. |
| Top-up | Supports amount selection, payment-method selection, confirmation, payment-specific result states, and return to wallet/transaction detail. |
| Withdrawals | Supports account/channel selection, validation, OTP request, withdrawal submission, and confirmation/error states. |
| Profile | Supports profile/address editing, password change, RFID add/edit/delete, and notification preferences. |
| Content/support | Shows organization-specific news, terms, refund policy, FAQ, support resources, and contact actions. |

## Baseline acceptance checks for the new app

Before API migration changes are evaluated, the new app should match these properties:

1. Protected routes redirect unauthenticated users to `/signin`.
2. Public auth pages expose the same route names and initial disabled/enabled states.
3. Auth page navigation links resolve to the same destinations.
4. The customer shell preserves desktop/mobile navigation and organization branding behavior.
5. Authenticated feature behavior is checked with a dedicated test account before declaring parity.
6. Any intentional difference is recorded in the migration matrix with its reason.

## Remaining baseline work

Live verification still needs:

- A non-production test account or approved staging credentials.
- A fixed organization code and test data.
- At least one station, connector, session, transaction, wallet, and RFID record.
- A controlled way to test QR/camera and live stream behavior.
