This commit is contained in:
Tomas Dvorak
2025-10-19 17:16:57 +02:00
parent e9a63073e5
commit 77213f4e83
76 changed files with 9728 additions and 935 deletions
+62
View File
@@ -247,3 +247,65 @@ The Website ID is stored in-memory by the backend after auto-creation. To make i
- In development, it allows localhost
- The manual UI provides explicit control over website creation
- You can create multiple websites for different domains if needed
## Umami v2 Compatibility Update (Latest Fix)
### Problem with Umami v2
In Umami v2, when users are part of teams, creating a website may require specifying a `teamId`. Without this parameter, the website creation request could fail.
### Solution Implemented
Updated `CreateWebsite()` method in `umami_service.go` to:
1. **Fetch current user information** via `POST /api/auth/verify`
2. **Retrieve user's teams** via `GET /api/users/:userId/teams`
3. **Automatically use the first available team** when creating a website
4. **Gracefully degrade** if teams cannot be fetched (continues without teamId)
### New Methods Added
```go
// GetCurrentUser - Retrieves authenticated user info from Umami
func (u *UmamiService) GetCurrentUser() (map[string]interface{}, error)
// GetUserTeams - Retrieves user's teams from Umami
func (u *UmamiService) GetUserTeams(userID string) ([]UmamiTeam, error)
```
### Updated CreateWebsite Flow
```
1. Authenticate with Umami
2. Get current user info (to obtain user ID)
3. Fetch user's teams (if user has teams)
4. Prepare website creation request with:
- name: Website name
- domain: Website domain
- teamId: First available team ID (optional)
5. Send POST /api/websites with Authorization Bearer token
6. Return website ID on success
```
### Enhanced Error Logging
All error messages now include detailed response bodies from Umami API for easier debugging:
- Authentication failures show full error response
- Website creation errors display Umami's error message
- Team fetch failures log warnings but don't block website creation
### Testing the Fix
To verify the fix works:
1. **Check backend logs** during website creation - you should see:
```
Creating Umami website: name='...', domain='...'
Using team ID: xxx-xxx-xxx (team name: ...)
Sending website creation request to Umami API: https://umami.tdvorak.dev/api/websites
Successfully created Umami website: ... (ID: xxx, Domain: ...)
```
2. **If teams aren't available**, you'll see:
```
Failed to fetch user teams (continuing without team): ...
Successfully created Umami website: ... (ID: xxx, Domain: ...)
```
3. **Monitor for creation errors** - detailed error messages will help diagnose issues
This update ensures compatibility with both Umami v1 (no teams) and Umami v2 (with teams).