mirror of
https://github.com/marcusDenslow/terminalShop.git
synced 2026-10-26 10:18:46 +01:00
previously main.go handled auth directly, it connected to the database, ran migrations, created a JWT manager and SSHAuthService, and authenticated the SSH key before the TUI even started. this commit rips all of that out Auth now happens inside the TUI during the splash screen via splashAuthCmd, which calls the /auth/token endpoint. if no user exists or the fingerprint it auto-creates one using the SSH public ke, so there is no longer a separate registartion flow. The token and user com back in the response. once authed splashViewInitCmd fires a single /view/init request that loads everything needed to start the app, products, cart, addresses, cards, and orders, before switching to the shop page on the model side, User/*models.user and gossh.PublicKey were replaced with plain Fingerprint and SSHPublicKeyStr strings, and NewModelWithAuth was updated too
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package tui
|
|
|
|
import (
|
|
"fmt"
|
|
"terminalShop/pkg/api"
|
|
"terminalShop/pkg/models"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
type DelayCompleteMsg struct{}
|
|
type splashCursorTickMsg struct{}
|
|
|
|
type SplashAuthMsg struct {
|
|
Token string
|
|
User models.PublicUser
|
|
Err error
|
|
}
|
|
|
|
type ViewInitMsg struct {
|
|
Data api.ViewInitData
|
|
Err error
|
|
}
|
|
|
|
func (m Model) splashAuthCmd() tea.Msg {
|
|
token, user, err := m.APIClient.GetOrCreateToken(
|
|
m.Fingerprint,
|
|
m.SSHPublicKeyStr,
|
|
m.AuthFingerprintKey,
|
|
)
|
|
if err != nil {
|
|
return SplashAuthMsg{Err: fmt.Errorf("auth failed: %w", err)}
|
|
}
|
|
return SplashAuthMsg{Token: token, User: user}
|
|
}
|
|
|
|
func (m Model) splashViewInitCmd() tea.Msg {
|
|
data, err := m.APIClient.GetViewInit()
|
|
if err != nil {
|
|
return ViewInitMsg{Err: fmt.Errorf("failed to load data: %w", err)}
|
|
}
|
|
return ViewInitMsg{Data: data}
|
|
}
|
|
|
|
func (m Model) SplashView() string {
|
|
accent := lipgloss.NewStyle().Foreground(lipgloss.Color("#AAAAAA")).Bold(true)
|
|
|
|
var cursor string
|
|
if m.splashCursor {
|
|
cursor = lipgloss.NewStyle().Background(lipgloss.Color("#4682B4")).Render(" ")
|
|
} else {
|
|
cursor = " "
|
|
}
|
|
|
|
logo := accent.Render("terminal coffe") + cursor
|
|
|
|
content := lipgloss.JoinVertical(
|
|
lipgloss.Center,
|
|
logo,
|
|
)
|
|
|
|
return lipgloss.Place(
|
|
m.viewportWidth,
|
|
m.viewportHeight,
|
|
lipgloss.Center,
|
|
lipgloss.Center,
|
|
content,
|
|
)
|
|
}
|