Spaces:
Runtime error
Runtime error
deploy: update
Browse files
alembic/versions/e5f6a7b8c9d0_add_users_and_spec_user_id.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add users table and user_id to spec_documents
|
| 2 |
+
|
| 3 |
+
Revision ID: e5f6a7b8c9d0
|
| 4 |
+
Revises: d4e5f6a7b8c9
|
| 5 |
+
Create Date: 2026-05-29
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
from alembic import op
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
|
| 11 |
+
revision: str = "e5f6a7b8c9d0"
|
| 12 |
+
down_revision: Union[str, None] = "d4e5f6a7b8c9"
|
| 13 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 14 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def upgrade() -> None:
|
| 18 |
+
op.execute("""
|
| 19 |
+
CREATE TABLE IF NOT EXISTS users (
|
| 20 |
+
id VARCHAR NOT NULL PRIMARY KEY,
|
| 21 |
+
username VARCHAR NOT NULL UNIQUE,
|
| 22 |
+
hashed_password VARCHAR NOT NULL,
|
| 23 |
+
created_at TIMESTAMP DEFAULT NOW()
|
| 24 |
+
)
|
| 25 |
+
""")
|
| 26 |
+
op.execute("CREATE INDEX IF NOT EXISTS ix_users_username ON users (username)")
|
| 27 |
+
|
| 28 |
+
op.execute("""
|
| 29 |
+
ALTER TABLE spec_documents
|
| 30 |
+
ADD COLUMN IF NOT EXISTS user_id VARCHAR
|
| 31 |
+
""")
|
| 32 |
+
op.execute("CREATE INDEX IF NOT EXISTS ix_spec_documents_user_id ON spec_documents (user_id)")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def downgrade() -> None:
|
| 36 |
+
op.execute("DROP INDEX IF EXISTS ix_spec_documents_user_id")
|
| 37 |
+
op.execute("ALTER TABLE spec_documents DROP COLUMN IF EXISTS user_id")
|
| 38 |
+
op.execute("DROP INDEX IF EXISTS ix_users_username")
|
| 39 |
+
op.execute("DROP TABLE IF EXISTS users")
|
backend/app/api/routes/auth.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter, Depends, HTTPException
|
| 2 |
from pydantic import BaseModel
|
|
|
|
| 3 |
|
| 4 |
-
from backend
|
| 5 |
-
from backend.core.
|
| 6 |
|
| 7 |
router = APIRouter(prefix="/auth")
|
| 8 |
|
|
@@ -12,11 +15,42 @@ class LoginRequest(BaseModel):
|
|
| 12 |
password: str
|
| 13 |
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
@router.post("/login")
|
| 16 |
-
def login(body: LoginRequest):
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
raise HTTPException(status_code=401, detail="Invalid credentials")
|
| 19 |
-
token = create_access_token(
|
| 20 |
return {"access_token": token, "token_type": "bearer"}
|
| 21 |
|
| 22 |
|
|
|
|
| 1 |
+
import uuid
|
| 2 |
+
|
| 3 |
from fastapi import APIRouter, Depends, HTTPException
|
| 4 |
from pydantic import BaseModel
|
| 5 |
+
from sqlalchemy.orm import Session
|
| 6 |
|
| 7 |
+
from backend import database
|
| 8 |
+
from backend.core.auth import create_access_token, hash_password, verify_password, verify_token
|
| 9 |
|
| 10 |
router = APIRouter(prefix="/auth")
|
| 11 |
|
|
|
|
| 15 |
password: str
|
| 16 |
|
| 17 |
|
| 18 |
+
class RegisterRequest(BaseModel):
|
| 19 |
+
username: str
|
| 20 |
+
password: str
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@router.post("/register")
|
| 24 |
+
def register(body: RegisterRequest, db: Session = Depends(database.get_db)):
|
| 25 |
+
username = body.username.strip().lower()
|
| 26 |
+
if len(username) < 3:
|
| 27 |
+
raise HTTPException(status_code=400, detail="Username must be at least 3 characters.")
|
| 28 |
+
if len(body.password) < 6:
|
| 29 |
+
raise HTTPException(status_code=400, detail="Password must be at least 6 characters.")
|
| 30 |
+
|
| 31 |
+
existing = db.query(database.User).filter(database.User.username == username).first()
|
| 32 |
+
if existing:
|
| 33 |
+
raise HTTPException(status_code=409, detail="Username already taken.")
|
| 34 |
+
|
| 35 |
+
user = database.User(
|
| 36 |
+
id=str(uuid.uuid4()),
|
| 37 |
+
username=username,
|
| 38 |
+
hashed_password=hash_password(body.password),
|
| 39 |
+
)
|
| 40 |
+
db.add(user)
|
| 41 |
+
db.commit()
|
| 42 |
+
|
| 43 |
+
token = create_access_token(username)
|
| 44 |
+
return {"access_token": token, "token_type": "bearer"}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
@router.post("/login")
|
| 48 |
+
def login(body: LoginRequest, db: Session = Depends(database.get_db)):
|
| 49 |
+
username = body.username.strip().lower()
|
| 50 |
+
user = db.query(database.User).filter(database.User.username == username).first()
|
| 51 |
+
if not user or not verify_password(body.password, user.hashed_password):
|
| 52 |
raise HTTPException(status_code=401, detail="Invalid credentials")
|
| 53 |
+
token = create_access_token(username)
|
| 54 |
return {"access_token": token, "token_type": "bearer"}
|
| 55 |
|
| 56 |
|
backend/app/api/routes/specs.py
CHANGED
|
@@ -8,6 +8,7 @@ from sqlalchemy.orm import Session
|
|
| 8 |
from sqlalchemy.orm.attributes import flag_modified
|
| 9 |
|
| 10 |
from backend import database, schemas
|
|
|
|
| 11 |
from backend.core.crypto import decrypt_credentials, encrypt_credentials
|
| 12 |
from backend.core.logging import get_logger
|
| 13 |
from backend.services.swagger_parser import parse_spec
|
|
@@ -19,7 +20,11 @@ logger = get_logger(__name__)
|
|
| 19 |
|
| 20 |
|
| 21 |
@router.post("/upload-spec")
|
| 22 |
-
async def upload_spec(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
try:
|
| 24 |
content = await file.read()
|
| 25 |
if len(content) > 5 * 1024 * 1024:
|
|
@@ -54,6 +59,7 @@ async def upload_spec(file: UploadFile = File(...), db: Session = Depends(databa
|
|
| 54 |
|
| 55 |
spec_doc = database.SpecDocument(
|
| 56 |
id=spec_id,
|
|
|
|
| 57 |
name=file.filename,
|
| 58 |
raw_content=decoded_content,
|
| 59 |
parsed_json=safe_spec,
|
|
@@ -76,8 +82,13 @@ async def upload_spec(file: UploadFile = File(...), db: Session = Depends(databa
|
|
| 76 |
|
| 77 |
|
| 78 |
@router.get("/specs")
|
| 79 |
-
def list_specs(db: Session = Depends(database.get_db)):
|
| 80 |
-
specs =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
return [
|
| 82 |
{"id": s.id, "name": s.name, "base_url": s.base_url or "", "uploaded_at": s.uploaded_at.isoformat()}
|
| 83 |
for s in specs
|
|
@@ -85,8 +96,11 @@ def list_specs(db: Session = Depends(database.get_db)):
|
|
| 85 |
|
| 86 |
|
| 87 |
@router.get("/specs/{spec_id}")
|
| 88 |
-
def get_spec(spec_id: str, db: Session = Depends(database.get_db)):
|
| 89 |
-
spec = db.query(database.SpecDocument).filter(
|
|
|
|
|
|
|
|
|
|
| 90 |
if not spec:
|
| 91 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 92 |
return {
|
|
@@ -102,8 +116,11 @@ def get_spec(spec_id: str, db: Session = Depends(database.get_db)):
|
|
| 102 |
|
| 103 |
|
| 104 |
@router.patch("/specs/{spec_id}")
|
| 105 |
-
def update_spec(spec_id: str, payload: dict, db: Session = Depends(database.get_db)):
|
| 106 |
-
spec = db.query(database.SpecDocument).filter(
|
|
|
|
|
|
|
|
|
|
| 107 |
if not spec:
|
| 108 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 109 |
if "base_url" in payload:
|
|
@@ -113,8 +130,11 @@ def update_spec(spec_id: str, payload: dict, db: Session = Depends(database.get_
|
|
| 113 |
|
| 114 |
|
| 115 |
@router.delete("/specs/{spec_id}")
|
| 116 |
-
def delete_spec(spec_id: str, db: Session = Depends(database.get_db)):
|
| 117 |
-
spec = db.query(database.SpecDocument).filter(
|
|
|
|
|
|
|
|
|
|
| 118 |
if not spec:
|
| 119 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 120 |
|
|
@@ -134,16 +154,22 @@ def delete_spec(spec_id: str, db: Session = Depends(database.get_db)):
|
|
| 134 |
|
| 135 |
|
| 136 |
@router.get("/specs/{spec_id}/credentials")
|
| 137 |
-
def get_credentials(spec_id: str, db: Session = Depends(database.get_db)):
|
| 138 |
-
spec = db.query(database.SpecDocument).filter(
|
|
|
|
|
|
|
|
|
|
| 139 |
if not spec:
|
| 140 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 141 |
return decrypt_credentials(spec.login_credentials or {})
|
| 142 |
|
| 143 |
|
| 144 |
@router.post("/specs/{spec_id}/credentials")
|
| 145 |
-
def save_credentials(spec_id: str, payload: schemas.CredentialUpdate, db: Session = Depends(database.get_db)):
|
| 146 |
-
spec = db.query(database.SpecDocument).filter(
|
|
|
|
|
|
|
|
|
|
| 147 |
if not spec:
|
| 148 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 149 |
|
|
|
|
| 8 |
from sqlalchemy.orm.attributes import flag_modified
|
| 9 |
|
| 10 |
from backend import database, schemas
|
| 11 |
+
from backend.core.auth import verify_token
|
| 12 |
from backend.core.crypto import decrypt_credentials, encrypt_credentials
|
| 13 |
from backend.core.logging import get_logger
|
| 14 |
from backend.services.swagger_parser import parse_spec
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
@router.post("/upload-spec")
|
| 23 |
+
async def upload_spec(
|
| 24 |
+
file: UploadFile = File(...),
|
| 25 |
+
db: Session = Depends(database.get_db),
|
| 26 |
+
current_user: str = Depends(verify_token),
|
| 27 |
+
):
|
| 28 |
try:
|
| 29 |
content = await file.read()
|
| 30 |
if len(content) > 5 * 1024 * 1024:
|
|
|
|
| 59 |
|
| 60 |
spec_doc = database.SpecDocument(
|
| 61 |
id=spec_id,
|
| 62 |
+
user_id=current_user,
|
| 63 |
name=file.filename,
|
| 64 |
raw_content=decoded_content,
|
| 65 |
parsed_json=safe_spec,
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
@router.get("/specs")
|
| 85 |
+
def list_specs(db: Session = Depends(database.get_db), current_user: str = Depends(verify_token)):
|
| 86 |
+
specs = (
|
| 87 |
+
db.query(database.SpecDocument)
|
| 88 |
+
.filter(database.SpecDocument.user_id == current_user)
|
| 89 |
+
.order_by(database.SpecDocument.uploaded_at.desc())
|
| 90 |
+
.all()
|
| 91 |
+
)
|
| 92 |
return [
|
| 93 |
{"id": s.id, "name": s.name, "base_url": s.base_url or "", "uploaded_at": s.uploaded_at.isoformat()}
|
| 94 |
for s in specs
|
|
|
|
| 96 |
|
| 97 |
|
| 98 |
@router.get("/specs/{spec_id}")
|
| 99 |
+
def get_spec(spec_id: str, db: Session = Depends(database.get_db), current_user: str = Depends(verify_token)):
|
| 100 |
+
spec = db.query(database.SpecDocument).filter(
|
| 101 |
+
database.SpecDocument.id == spec_id,
|
| 102 |
+
database.SpecDocument.user_id == current_user,
|
| 103 |
+
).first()
|
| 104 |
if not spec:
|
| 105 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 106 |
return {
|
|
|
|
| 116 |
|
| 117 |
|
| 118 |
@router.patch("/specs/{spec_id}")
|
| 119 |
+
def update_spec(spec_id: str, payload: dict, db: Session = Depends(database.get_db), current_user: str = Depends(verify_token)):
|
| 120 |
+
spec = db.query(database.SpecDocument).filter(
|
| 121 |
+
database.SpecDocument.id == spec_id,
|
| 122 |
+
database.SpecDocument.user_id == current_user,
|
| 123 |
+
).first()
|
| 124 |
if not spec:
|
| 125 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 126 |
if "base_url" in payload:
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
@router.delete("/specs/{spec_id}")
|
| 133 |
+
def delete_spec(spec_id: str, db: Session = Depends(database.get_db), current_user: str = Depends(verify_token)):
|
| 134 |
+
spec = db.query(database.SpecDocument).filter(
|
| 135 |
+
database.SpecDocument.id == spec_id,
|
| 136 |
+
database.SpecDocument.user_id == current_user,
|
| 137 |
+
).first()
|
| 138 |
if not spec:
|
| 139 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 140 |
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
@router.get("/specs/{spec_id}/credentials")
|
| 157 |
+
def get_credentials(spec_id: str, db: Session = Depends(database.get_db), current_user: str = Depends(verify_token)):
|
| 158 |
+
spec = db.query(database.SpecDocument).filter(
|
| 159 |
+
database.SpecDocument.id == spec_id,
|
| 160 |
+
database.SpecDocument.user_id == current_user,
|
| 161 |
+
).first()
|
| 162 |
if not spec:
|
| 163 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 164 |
return decrypt_credentials(spec.login_credentials or {})
|
| 165 |
|
| 166 |
|
| 167 |
@router.post("/specs/{spec_id}/credentials")
|
| 168 |
+
def save_credentials(spec_id: str, payload: schemas.CredentialUpdate, db: Session = Depends(database.get_db), current_user: str = Depends(verify_token)):
|
| 169 |
+
spec = db.query(database.SpecDocument).filter(
|
| 170 |
+
database.SpecDocument.id == spec_id,
|
| 171 |
+
database.SpecDocument.user_id == current_user,
|
| 172 |
+
).first()
|
| 173 |
if not spec:
|
| 174 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 175 |
|
backend/core/auth.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from datetime import datetime, timedelta, timezone
|
| 2 |
|
| 3 |
import jwt
|
|
@@ -9,6 +11,22 @@ from backend.core.config import settings
|
|
| 9 |
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def create_access_token(username: str) -> str:
|
| 13 |
expire = datetime.now(timezone.utc) + timedelta(hours=settings.JWT_EXPIRE_HOURS)
|
| 14 |
return jwt.encode({"sub": username, "exp": expire}, settings.JWT_SECRET, algorithm="HS256")
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
import os
|
| 3 |
from datetime import datetime, timedelta, timezone
|
| 4 |
|
| 5 |
import jwt
|
|
|
|
| 11 |
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")
|
| 12 |
|
| 13 |
|
| 14 |
+
def hash_password(password: str) -> str:
|
| 15 |
+
salt = os.urandom(16)
|
| 16 |
+
dk = hashlib.pbkdf2_hmac("sha256", password.encode(), salt, 260_000)
|
| 17 |
+
return salt.hex() + "$" + dk.hex()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def verify_password(password: str, hashed: str) -> bool:
|
| 21 |
+
try:
|
| 22 |
+
salt_hex, dk_hex = hashed.split("$", 1)
|
| 23 |
+
salt = bytes.fromhex(salt_hex)
|
| 24 |
+
dk = hashlib.pbkdf2_hmac("sha256", password.encode(), salt, 260_000)
|
| 25 |
+
return dk.hex() == dk_hex
|
| 26 |
+
except Exception:
|
| 27 |
+
return False
|
| 28 |
+
|
| 29 |
+
|
| 30 |
def create_access_token(username: str) -> str:
|
| 31 |
expire = datetime.now(timezone.utc) + timedelta(hours=settings.JWT_EXPIRE_HOURS)
|
| 32 |
return jwt.encode({"sub": username, "exp": expire}, settings.JWT_SECRET, algorithm="HS256")
|
backend/database.py
CHANGED
|
@@ -39,10 +39,20 @@ asset_collections = Table(
|
|
| 39 |
Column("collection_id", String, ForeignKey("collections.id"), primary_key=True)
|
| 40 |
)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
class SpecDocument(Base):
|
| 43 |
__tablename__ = "spec_documents"
|
| 44 |
|
| 45 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
|
|
| 46 |
name = Column(String, nullable=False)
|
| 47 |
raw_content = Column(Text, nullable=False)
|
| 48 |
parsed_json = Column(JSON, nullable=False)
|
|
|
|
| 39 |
Column("collection_id", String, ForeignKey("collections.id"), primary_key=True)
|
| 40 |
)
|
| 41 |
|
| 42 |
+
class User(Base):
|
| 43 |
+
__tablename__ = "users"
|
| 44 |
+
|
| 45 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 46 |
+
username = Column(String, unique=True, nullable=False, index=True)
|
| 47 |
+
hashed_password = Column(String, nullable=False)
|
| 48 |
+
created_at = Column(DateTime, default=_utcnow)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
class SpecDocument(Base):
|
| 52 |
__tablename__ = "spec_documents"
|
| 53 |
|
| 54 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 55 |
+
user_id = Column(String, nullable=True, index=True)
|
| 56 |
name = Column(String, nullable=False)
|
| 57 |
raw_content = Column(Text, nullable=False)
|
| 58 |
parsed_json = Column(JSON, nullable=False)
|
frontend-react/src/components/LoginPage.jsx
CHANGED
|
@@ -1,141 +1,350 @@
|
|
| 1 |
import React, { useState } from 'react';
|
| 2 |
import { AuthService } from '../services/api';
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
export default function LoginPage({ onLogin }) {
|
|
|
|
| 5 |
const [username, setUsername] = useState('');
|
| 6 |
const [password, setPassword] = useState('');
|
| 7 |
-
const [
|
| 8 |
-
const [
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
const handleSubmit = async (e) => {
|
| 11 |
e.preventDefault();
|
| 12 |
setError('');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
setLoading(true);
|
| 14 |
try {
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
onLogin();
|
| 17 |
-
} catch {
|
| 18 |
-
setError('Invalid username or password.');
|
| 19 |
} finally {
|
| 20 |
setLoading(false);
|
| 21 |
}
|
| 22 |
};
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return (
|
| 25 |
<div style={{
|
| 26 |
minHeight: '100vh',
|
| 27 |
display: 'flex',
|
| 28 |
-
alignItems: 'center',
|
| 29 |
-
justifyContent: 'center',
|
| 30 |
background: 'var(--bg-0)',
|
|
|
|
| 31 |
}}>
|
|
|
|
|
|
|
| 32 |
<div style={{
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
padding: '
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
}}>
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
<div style={{
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
fontWeight: 700,
|
| 44 |
color: 'var(--fg-0)',
|
| 45 |
fontFamily: 'var(--font-mono)',
|
| 46 |
-
letterSpacing: '-0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}}>
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
</div>
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</div>
|
| 53 |
-
</div>
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
<
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
style={{
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
border: '
|
| 72 |
-
borderRadius:
|
| 73 |
-
color: 'var(--fg-0)',
|
| 74 |
fontSize: 14,
|
|
|
|
|
|
|
|
|
|
| 75 |
fontFamily: 'var(--font-mono)',
|
| 76 |
-
|
| 77 |
}}
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
<div>
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
type="password"
|
| 87 |
-
value={password}
|
| 88 |
-
onChange={(e) => setPassword(e.target.value)}
|
| 89 |
-
required
|
| 90 |
style={{
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
padding: '9px 12px',
|
| 94 |
-
background: 'var(--bg-3)',
|
| 95 |
-
border: '1px solid var(--line-2)',
|
| 96 |
-
borderRadius: 7,
|
| 97 |
-
color: 'var(--fg-0)',
|
| 98 |
-
fontSize: 14,
|
| 99 |
-
fontFamily: 'var(--font-mono)',
|
| 100 |
-
outline: 'none',
|
| 101 |
}}
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
</div>
|
| 104 |
-
|
| 105 |
-
{error && (
|
| 106 |
-
<div style={{
|
| 107 |
-
padding: '8px 12px',
|
| 108 |
-
background: 'var(--err-soft)',
|
| 109 |
-
border: '1px solid var(--err)',
|
| 110 |
-
borderRadius: 7,
|
| 111 |
-
color: 'var(--err)',
|
| 112 |
-
fontSize: 13,
|
| 113 |
-
}}>
|
| 114 |
-
{error}
|
| 115 |
-
</div>
|
| 116 |
-
)}
|
| 117 |
-
|
| 118 |
-
<button
|
| 119 |
-
type="submit"
|
| 120 |
-
disabled={loading}
|
| 121 |
-
style={{
|
| 122 |
-
marginTop: 6,
|
| 123 |
-
padding: '10px',
|
| 124 |
-
background: 'var(--accent)',
|
| 125 |
-
color: 'var(--accent-fg)',
|
| 126 |
-
border: 'none',
|
| 127 |
-
borderRadius: 7,
|
| 128 |
-
fontSize: 14,
|
| 129 |
-
fontWeight: 600,
|
| 130 |
-
cursor: loading ? 'not-allowed' : 'pointer',
|
| 131 |
-
opacity: loading ? 0.7 : 1,
|
| 132 |
-
fontFamily: 'var(--font-mono)',
|
| 133 |
-
transition: 'opacity 0.15s',
|
| 134 |
-
}}
|
| 135 |
-
>
|
| 136 |
-
{loading ? 'Signing in…' : 'Sign in'}
|
| 137 |
-
</button>
|
| 138 |
-
</form>
|
| 139 |
</div>
|
| 140 |
</div>
|
| 141 |
);
|
|
|
|
| 1 |
import React, { useState } from 'react';
|
| 2 |
import { AuthService } from '../services/api';
|
| 3 |
|
| 4 |
+
const features = [
|
| 5 |
+
{
|
| 6 |
+
icon: '⚡',
|
| 7 |
+
title: 'Automated Workflows',
|
| 8 |
+
desc: 'Build and run multi-step API test flows without writing boilerplate.',
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
icon: '🔍',
|
| 12 |
+
title: 'Smart Diff & Validation',
|
| 13 |
+
desc: 'Instantly compare responses and catch regressions before they ship.',
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
icon: '📁',
|
| 17 |
+
title: 'Spec-driven Testing',
|
| 18 |
+
desc: 'Import OpenAPI specs and generate tests from your existing contracts.',
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
icon: '🤖',
|
| 22 |
+
title: 'AI Assistant',
|
| 23 |
+
desc: 'Ask questions about your APIs and get context-aware suggestions.',
|
| 24 |
+
},
|
| 25 |
+
];
|
| 26 |
+
|
| 27 |
export default function LoginPage({ onLogin }) {
|
| 28 |
+
const [mode, setMode] = useState('login'); // 'login' | 'register'
|
| 29 |
const [username, setUsername] = useState('');
|
| 30 |
const [password, setPassword] = useState('');
|
| 31 |
+
const [confirm, setConfirm] = useState('');
|
| 32 |
+
const [error, setError] = useState('');
|
| 33 |
+
const [loading, setLoading] = useState(false);
|
| 34 |
+
|
| 35 |
+
const switchMode = (m) => { setMode(m); setError(''); setPassword(''); setConfirm(''); };
|
| 36 |
|
| 37 |
const handleSubmit = async (e) => {
|
| 38 |
e.preventDefault();
|
| 39 |
setError('');
|
| 40 |
+
if (mode === 'register' && password !== confirm) {
|
| 41 |
+
setError('Passwords do not match.');
|
| 42 |
+
return;
|
| 43 |
+
}
|
| 44 |
setLoading(true);
|
| 45 |
try {
|
| 46 |
+
if (mode === 'register') {
|
| 47 |
+
await AuthService.register(username.trim(), password);
|
| 48 |
+
} else {
|
| 49 |
+
await AuthService.login(username.trim(), password);
|
| 50 |
+
}
|
| 51 |
onLogin();
|
| 52 |
+
} catch (err) {
|
| 53 |
+
setError(err.message || (mode === 'register' ? 'Registration failed.' : 'Invalid username or password.'));
|
| 54 |
} finally {
|
| 55 |
setLoading(false);
|
| 56 |
}
|
| 57 |
};
|
| 58 |
|
| 59 |
+
const inputStyle = {
|
| 60 |
+
width: '100%',
|
| 61 |
+
boxSizing: 'border-box',
|
| 62 |
+
padding: '10px 13px',
|
| 63 |
+
background: 'var(--bg-3)',
|
| 64 |
+
border: '1px solid var(--line-2)',
|
| 65 |
+
borderRadius: 8,
|
| 66 |
+
color: 'var(--fg-0)',
|
| 67 |
+
fontSize: 14,
|
| 68 |
+
fontFamily: 'var(--font-mono)',
|
| 69 |
+
outline: 'none',
|
| 70 |
+
transition: 'border-color 0.15s',
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
return (
|
| 74 |
<div style={{
|
| 75 |
minHeight: '100vh',
|
| 76 |
display: 'flex',
|
|
|
|
|
|
|
| 77 |
background: 'var(--bg-0)',
|
| 78 |
+
fontFamily: 'var(--font-sans)',
|
| 79 |
}}>
|
| 80 |
+
|
| 81 |
+
{/* ── Left: Landing panel ─────────────────────────────────── */}
|
| 82 |
<div style={{
|
| 83 |
+
flex: 1,
|
| 84 |
+
display: 'flex',
|
| 85 |
+
flexDirection: 'column',
|
| 86 |
+
justifyContent: 'center',
|
| 87 |
+
padding: '60px 64px',
|
| 88 |
+
background: 'var(--bg-1)',
|
| 89 |
+
borderRight: '1px solid var(--line-1)',
|
| 90 |
+
minWidth: 0,
|
| 91 |
}}>
|
| 92 |
+
|
| 93 |
+
{/* Logo / brand */}
|
| 94 |
+
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 48 }}>
|
| 95 |
<div style={{
|
| 96 |
+
width: 36,
|
| 97 |
+
height: 36,
|
| 98 |
+
borderRadius: 9,
|
| 99 |
+
background: 'var(--accent)',
|
| 100 |
+
display: 'flex',
|
| 101 |
+
alignItems: 'center',
|
| 102 |
+
justifyContent: 'center',
|
| 103 |
+
fontSize: 18,
|
| 104 |
+
fontWeight: 800,
|
| 105 |
+
color: 'var(--accent-fg)',
|
| 106 |
+
fontFamily: 'var(--font-mono)',
|
| 107 |
+
flexShrink: 0,
|
| 108 |
+
}}>A</div>
|
| 109 |
+
<span style={{
|
| 110 |
+
fontSize: 17,
|
| 111 |
fontWeight: 700,
|
| 112 |
color: 'var(--fg-0)',
|
| 113 |
fontFamily: 'var(--font-mono)',
|
| 114 |
+
letterSpacing: '-0.3px',
|
| 115 |
+
}}>apitest</span>
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
{/* Hero headline */}
|
| 119 |
+
<h1 style={{
|
| 120 |
+
margin: '0 0 16px',
|
| 121 |
+
fontSize: 36,
|
| 122 |
+
fontWeight: 800,
|
| 123 |
+
color: 'var(--fg-0)',
|
| 124 |
+
lineHeight: 1.15,
|
| 125 |
+
letterSpacing: '-1px',
|
| 126 |
+
maxWidth: 480,
|
| 127 |
+
}}>
|
| 128 |
+
Test your APIs<br/>
|
| 129 |
+
<span style={{ color: 'var(--accent)' }}>faster and smarter.</span>
|
| 130 |
+
</h1>
|
| 131 |
+
|
| 132 |
+
<p style={{
|
| 133 |
+
margin: '0 0 48px',
|
| 134 |
+
fontSize: 15,
|
| 135 |
+
color: 'var(--fg-2)',
|
| 136 |
+
lineHeight: 1.65,
|
| 137 |
+
maxWidth: 400,
|
| 138 |
+
}}>
|
| 139 |
+
A unified workspace for designing, running, and validating API tests —
|
| 140 |
+
powered by AI and driven by your specs.
|
| 141 |
+
</p>
|
| 142 |
+
|
| 143 |
+
{/* Feature list */}
|
| 144 |
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
|
| 145 |
+
{features.map(f => (
|
| 146 |
+
<div key={f.title} style={{ display: 'flex', gap: 16, alignItems: 'flex-start' }}>
|
| 147 |
+
<div style={{
|
| 148 |
+
width: 36,
|
| 149 |
+
height: 36,
|
| 150 |
+
borderRadius: 8,
|
| 151 |
+
background: 'var(--bg-2)',
|
| 152 |
+
border: '1px solid var(--line-2)',
|
| 153 |
+
display: 'flex',
|
| 154 |
+
alignItems: 'center',
|
| 155 |
+
justifyContent: 'center',
|
| 156 |
+
fontSize: 17,
|
| 157 |
+
flexShrink: 0,
|
| 158 |
+
}}>{f.icon}</div>
|
| 159 |
+
<div>
|
| 160 |
+
<div style={{ fontSize: 14, fontWeight: 600, color: 'var(--fg-0)', marginBottom: 3 }}>
|
| 161 |
+
{f.title}
|
| 162 |
+
</div>
|
| 163 |
+
<div style={{ fontSize: 13, color: 'var(--fg-2)', lineHeight: 1.55 }}>
|
| 164 |
+
{f.desc}
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
))}
|
| 169 |
+
</div>
|
| 170 |
+
</div>
|
| 171 |
+
|
| 172 |
+
{/* ── Right: Login panel ──────────────────────────────────── */}
|
| 173 |
+
<div style={{
|
| 174 |
+
width: 420,
|
| 175 |
+
flexShrink: 0,
|
| 176 |
+
display: 'flex',
|
| 177 |
+
flexDirection: 'column',
|
| 178 |
+
alignItems: 'center',
|
| 179 |
+
justifyContent: 'center',
|
| 180 |
+
padding: '60px 48px',
|
| 181 |
+
background: 'var(--bg-1)',
|
| 182 |
+
}}>
|
| 183 |
+
|
| 184 |
+
<div style={{
|
| 185 |
+
width: '100%',
|
| 186 |
+
maxWidth: 340,
|
| 187 |
+
background: 'var(--bg-2)',
|
| 188 |
+
border: '1px solid var(--line-2)',
|
| 189 |
+
borderRadius: 16,
|
| 190 |
+
padding: '36px 32px',
|
| 191 |
+
boxShadow: '0 8px 40px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.07)',
|
| 192 |
+
}}>
|
| 193 |
+
|
| 194 |
+
{/* Mode toggle tabs */}
|
| 195 |
+
<div style={{
|
| 196 |
+
display: 'flex',
|
| 197 |
+
background: 'var(--bg-3)',
|
| 198 |
+
borderRadius: 10,
|
| 199 |
+
padding: 3,
|
| 200 |
+
marginBottom: 28,
|
| 201 |
}}>
|
| 202 |
+
{['login', 'register'].map(m => (
|
| 203 |
+
<button
|
| 204 |
+
key={m}
|
| 205 |
+
type="button"
|
| 206 |
+
onClick={() => switchMode(m)}
|
| 207 |
+
style={{
|
| 208 |
+
flex: 1,
|
| 209 |
+
padding: '8px 0',
|
| 210 |
+
background: mode === m ? 'var(--bg-2)' : 'transparent',
|
| 211 |
+
border: mode === m ? '1px solid var(--line-2)' : '1px solid transparent',
|
| 212 |
+
borderRadius: 8,
|
| 213 |
+
color: mode === m ? 'var(--fg-0)' : 'var(--fg-2)',
|
| 214 |
+
fontSize: 13,
|
| 215 |
+
fontWeight: mode === m ? 600 : 400,
|
| 216 |
+
fontFamily: 'var(--font-mono)',
|
| 217 |
+
cursor: 'pointer',
|
| 218 |
+
transition: 'all 0.15s',
|
| 219 |
+
}}
|
| 220 |
+
>
|
| 221 |
+
{m === 'login' ? 'Sign in' : 'Sign up'}
|
| 222 |
+
</button>
|
| 223 |
+
))}
|
| 224 |
</div>
|
| 225 |
+
|
| 226 |
+
<div style={{ marginBottom: 24 }}>
|
| 227 |
+
<div style={{
|
| 228 |
+
fontSize: 20,
|
| 229 |
+
fontWeight: 700,
|
| 230 |
+
color: 'var(--fg-0)',
|
| 231 |
+
fontFamily: 'var(--font-mono)',
|
| 232 |
+
letterSpacing: '-0.5px',
|
| 233 |
+
marginBottom: 5,
|
| 234 |
+
}}>
|
| 235 |
+
{mode === 'login' ? 'Welcome back' : 'Create account'}
|
| 236 |
+
</div>
|
| 237 |
+
<div style={{ fontSize: 13, color: 'var(--fg-2)' }}>
|
| 238 |
+
{mode === 'login'
|
| 239 |
+
? 'Enter your credentials to continue.'
|
| 240 |
+
: 'Pick a username and password to get started.'}
|
| 241 |
+
</div>
|
| 242 |
</div>
|
|
|
|
| 243 |
|
| 244 |
+
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
|
| 245 |
+
|
| 246 |
+
<div>
|
| 247 |
+
<label style={{ display: 'block', fontSize: 12, fontWeight: 500, color: 'var(--fg-2)', marginBottom: 6 }}>
|
| 248 |
+
Username
|
| 249 |
+
</label>
|
| 250 |
+
<input
|
| 251 |
+
type="text"
|
| 252 |
+
value={username}
|
| 253 |
+
onChange={(e) => setUsername(e.target.value)}
|
| 254 |
+
autoFocus
|
| 255 |
+
required
|
| 256 |
+
placeholder="your-username"
|
| 257 |
+
style={inputStyle}
|
| 258 |
+
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
|
| 259 |
+
onBlur={e => e.target.style.borderColor = 'var(--line-2)'}
|
| 260 |
+
/>
|
| 261 |
+
</div>
|
| 262 |
+
|
| 263 |
+
<div>
|
| 264 |
+
<label style={{ display: 'block', fontSize: 12, fontWeight: 500, color: 'var(--fg-2)', marginBottom: 6 }}>
|
| 265 |
+
Password
|
| 266 |
+
</label>
|
| 267 |
+
<input
|
| 268 |
+
type="password"
|
| 269 |
+
value={password}
|
| 270 |
+
onChange={(e) => setPassword(e.target.value)}
|
| 271 |
+
required
|
| 272 |
+
placeholder="••••••••"
|
| 273 |
+
style={inputStyle}
|
| 274 |
+
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
|
| 275 |
+
onBlur={e => e.target.style.borderColor = 'var(--line-2)'}
|
| 276 |
+
/>
|
| 277 |
+
</div>
|
| 278 |
+
|
| 279 |
+
{mode === 'register' && (
|
| 280 |
+
<div>
|
| 281 |
+
<label style={{ display: 'block', fontSize: 12, fontWeight: 500, color: 'var(--fg-2)', marginBottom: 6 }}>
|
| 282 |
+
Confirm password
|
| 283 |
+
</label>
|
| 284 |
+
<input
|
| 285 |
+
type="password"
|
| 286 |
+
value={confirm}
|
| 287 |
+
onChange={(e) => setConfirm(e.target.value)}
|
| 288 |
+
required
|
| 289 |
+
placeholder="••••••••"
|
| 290 |
+
style={inputStyle}
|
| 291 |
+
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
|
| 292 |
+
onBlur={e => e.target.style.borderColor = 'var(--line-2)'}
|
| 293 |
+
/>
|
| 294 |
+
</div>
|
| 295 |
+
)}
|
| 296 |
+
|
| 297 |
+
{error && (
|
| 298 |
+
<div style={{
|
| 299 |
+
padding: '9px 13px',
|
| 300 |
+
background: 'var(--err-soft)',
|
| 301 |
+
border: '1px solid var(--err)',
|
| 302 |
+
borderRadius: 8,
|
| 303 |
+
color: 'var(--err)',
|
| 304 |
+
fontSize: 13,
|
| 305 |
+
}}>
|
| 306 |
+
{error}
|
| 307 |
+
</div>
|
| 308 |
+
)}
|
| 309 |
+
|
| 310 |
+
<button
|
| 311 |
+
type="submit"
|
| 312 |
+
disabled={loading}
|
| 313 |
style={{
|
| 314 |
+
marginTop: 4,
|
| 315 |
+
padding: '11px',
|
| 316 |
+
background: 'var(--accent)',
|
| 317 |
+
color: 'var(--accent-fg)',
|
| 318 |
+
border: 'none',
|
| 319 |
+
borderRadius: 8,
|
|
|
|
| 320 |
fontSize: 14,
|
| 321 |
+
fontWeight: 600,
|
| 322 |
+
cursor: loading ? 'not-allowed' : 'pointer',
|
| 323 |
+
opacity: loading ? 0.7 : 1,
|
| 324 |
fontFamily: 'var(--font-mono)',
|
| 325 |
+
transition: 'opacity 0.15s',
|
| 326 |
}}
|
| 327 |
+
>
|
| 328 |
+
{loading
|
| 329 |
+
? (mode === 'login' ? 'Signing in…' : 'Creating account…')
|
| 330 |
+
: (mode === 'login' ? 'Sign in →' : 'Create account →')}
|
| 331 |
+
</button>
|
| 332 |
+
</form>
|
| 333 |
|
| 334 |
+
<div style={{ marginTop: 24, fontSize: 12, color: 'var(--fg-3)', textAlign: 'center' }}>
|
| 335 |
+
{mode === 'login' ? "Don't have an account? " : 'Already have an account? '}
|
| 336 |
+
<button
|
| 337 |
+
type="button"
|
| 338 |
+
onClick={() => switchMode(mode === 'login' ? 'register' : 'login')}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
style={{
|
| 340 |
+
background: 'none', border: 'none', padding: 0,
|
| 341 |
+
color: 'var(--accent)', fontSize: 12, cursor: 'pointer', fontWeight: 600,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
}}
|
| 343 |
+
>
|
| 344 |
+
{mode === 'login' ? 'Sign up' : 'Sign in'}
|
| 345 |
+
</button>
|
| 346 |
</div>
|
| 347 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
</div>
|
| 349 |
</div>
|
| 350 |
);
|
frontend-react/src/services/api.js
CHANGED
|
@@ -43,6 +43,12 @@ api.interceptors.response.use(
|
|
| 43 |
);
|
| 44 |
|
| 45 |
export const AuthService = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
login: async (username, password) => {
|
| 47 |
// Uses plain axios (no token needed, no 401 redirect loop)
|
| 48 |
const response = await axios.post(`${API_BASE}/auth/login`, { username, password });
|
|
|
|
| 43 |
);
|
| 44 |
|
| 45 |
export const AuthService = {
|
| 46 |
+
register: async (username, password) => {
|
| 47 |
+
const response = await axios.post(`${API_BASE}/auth/register`, { username, password });
|
| 48 |
+
_token = response.data.access_token;
|
| 49 |
+
sessionStorage.setItem(SESSION_KEY, _token);
|
| 50 |
+
return response.data;
|
| 51 |
+
},
|
| 52 |
login: async (username, password) => {
|
| 53 |
// Uses plain axios (no token needed, no 401 redirect loop)
|
| 54 |
const response = await axios.post(`${API_BASE}/auth/login`, { username, password });
|