3.8 KiB
3.8 KiB
Feature Request: Authentication Support
Context: We are upgrading the "LiteRequest" Tauri + Vue application. Currently, it supports Headers, Params, and Body. Goal: Add a dedicated "Auth" tab in the Request Configuration area to support common authentication methods.
1. Functional Requirements
1.1 Supported Auth Types
The user should be able to select one of the following from a dropdown:
- No Auth (Default)
- Basic Auth: Inputs for
UsernameandPassword. - Bearer Token: Input for
Token(e.g., JWT). - API Key: Inputs for
Key,Value, and a selection forAdd To("Header" or "Query Params").
1.2 State Management
- Update
stores/requestStore.tsto include anauthstate object. - Structure:
state: { // ... existing state auth: { type: 'none', // 'none' | 'basic' | 'bearer' | 'api_key' basic: { username: '', password: '' }, bearer: { token: '' }, apiKey: { key: '', value: '', addTo: 'header' } // addTo: 'header' | 'query' } } - Persistence: These values should be saved to
localStoragealong with the request history (careful note: in a real app we would encrypt this, but for this local MVP, plain text storage is acceptable).
2. UI/UX Design
2.1 Request Panel Update
- In
RequestPanel.vue, add a new Tab labeled "Auth" (place it first, before "Params"). - Layout:
- Type Selector: A styled
<select>or dropdown menu at the top of the tab content. - Dynamic Form:
- If No Auth: Show a subtle message "This request does not use any authentication."
- If Basic Auth: Two fields (Username, Password). Password field must use type="password" with a toggle to show/hide.
- If Bearer Token: One large text area or input for the Token. Prefix it visually with "Bearer ".
- If API Key: Three inputs: Key (text), Value (text/password), Add To (Radio button or Select).
- Type Selector: A styled
2.2 Aesthetic Guidelines
- Maintain the Dark Mode (Slate/Zinc) theme.
- Inputs should look identical to the existing inputs in the "Headers" tab (rounded, dark background, border-slate-700).
- Use
lucide-vue-nexticons (e.g.,ShieldCheckicon for the Tab label).
3. Technical Implementation Details
A. Frontend Logic (requestStore.ts & Component)
- The Frontend needs to package this Auth data and send it to the Rust backend.
- Important: Do not manually inject these into the
headerslist in the frontend UI (to avoid state sync issues). Pass the auth configuration as a separate object to the Rust command.
B. Backend Logic (main.rs)
- Update the
execute_requestTauri command signature to accept anauthargument. - Logic Update:
- Use
reqwestbuilt-in methods: - Basic:
.basic_auth(username, Some(password)) - Bearer:
.bearer_auth(token) - API Key:
- If
addTo == "header": Manually.header(key, value) - If
addTo == "query": Manually append to the query params.
- If
- Use
4. Implementation Steps for AI
Please generate the code updates in the following order:
- Store Update: Modify
stores/requestStore.tsto add theauthstate structure. - UI Component: Create a new component
components/AuthPanel.vue(or code to be added insideRequestPanel.vue) that handles the form switching and inputs. - Rust Backend: Update
main.rs. Define theAuthstruct (usingserde::Deserialize) and update theexecute_requestlogic to apply the auth. - Integration: Show how to update the
execute_requestinvocation in the frontend to pass this new data.
Instruction to AI: Generate the code to implement these Authentication features. Ensure the UI matches the existing modern style (Tailwind CSS).