mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 18:46:42 +02:00
Replace 21 separate NestJS Matrix bot processes (~2.1 GB RAM, ~4.2 GB Docker images) with a single Go binary using plugin architecture (8.6 MB binary, ~30 MB RAM). New services: - services/mana-matrix-bot/ — Go Matrix bot with 21 plugins (mautrix-go, Redis sessions) - services/mana-api-gateway-go/ — Go API gateway (rate limiting, API keys, credit billing) Deleted: - 21 services/matrix-*-bot/ directories - packages/bot-services/ and packages/matrix-bot-common/ - Legacy deploy scripts and CI build jobs Updated: - docker-compose.macmini.yml: new Go services, legacy bots removed - CI/CD: change detection + build jobs for Go services - Root package.json: new dev:matrix, build:matrix, test:matrix scripts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// AuthClient handles login/logout via mana-core-auth.
|
|
type AuthClient struct {
|
|
backend *BackendClient
|
|
}
|
|
|
|
// LoginResponse holds the auth service login response.
|
|
type LoginResponse struct {
|
|
Token string `json:"token"`
|
|
RefreshToken string `json:"refreshToken"`
|
|
ExpiresIn int `json:"expiresIn"` // seconds
|
|
}
|
|
|
|
// NewAuthClient creates a new auth service client.
|
|
func NewAuthClient(authURL string) *AuthClient {
|
|
return &AuthClient{backend: NewBackendClient(authURL)}
|
|
}
|
|
|
|
// Login authenticates a user and returns a JWT token.
|
|
func (c *AuthClient) Login(ctx context.Context, email, password string) (*LoginResponse, error) {
|
|
body := map[string]string{
|
|
"email": email,
|
|
"password": password,
|
|
}
|
|
|
|
var resp LoginResponse
|
|
if err := c.backend.Post(ctx, "/api/v1/auth/login", "", body, &resp); err != nil {
|
|
return nil, fmt.Errorf("login failed: %w", err)
|
|
}
|
|
|
|
if resp.Token == "" {
|
|
return nil, fmt.Errorf("login: no token in response")
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|
|
|
|
// TokenExpiresAt calculates the expiry time from the login response.
|
|
func TokenExpiresAt(resp *LoginResponse) time.Time {
|
|
if resp.ExpiresIn > 0 {
|
|
return time.Now().Add(time.Duration(resp.ExpiresIn) * time.Second)
|
|
}
|
|
// Default: 24 hours
|
|
return time.Now().Add(24 * time.Hour)
|
|
}
|