v0.9.0 user and session management improvement, xterm.js addons
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/api/client.go
|
||||
package api
|
||||
|
||||
import (
|
||||
@ -226,6 +225,10 @@ func (c *Client) Login(identifier, password string) (*AuthResponse, error) {
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
func (c *Client) Logout() error {
|
||||
return c.doRequest("POST", "/api/v1/auth/logout", nil, nil)
|
||||
}
|
||||
|
||||
func (c *Client) GetCurrentUser() (*UserResponse, error) {
|
||||
var resp UserResponse
|
||||
err := c.doRequest("GET", "/api/v1/auth/me", nil, &resp)
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/api/types.go
|
||||
package api
|
||||
|
||||
import "time"
|
||||
@ -71,9 +70,11 @@ type BoardResponse struct {
|
||||
}
|
||||
|
||||
type AuthResponse struct {
|
||||
Token string `json:"token"`
|
||||
UserID string `json:"userId"`
|
||||
Username string `json:"username"`
|
||||
Token string `json:"token"`
|
||||
UserID string `json:"userId"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email,omitempty"`
|
||||
ExpiresAt time.Time `json:"expiresAt,omitempty"`
|
||||
}
|
||||
|
||||
type UserResponse struct {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/command/auth.go
|
||||
package command
|
||||
|
||||
import (
|
||||
@ -119,10 +118,20 @@ func loginHandler(s *session.Session, args []string) error {
|
||||
}
|
||||
|
||||
func logoutHandler(s *session.Session, args []string) error {
|
||||
c := s.GetClient().(*api.Client)
|
||||
|
||||
// Call server to invalidate session if authenticated
|
||||
if s.GetAuthToken() != "" {
|
||||
if err := c.Logout(); err != nil {
|
||||
// Log but don't fail - clear local state anyway
|
||||
display.Println(display.Yellow, "Server logout failed: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Clear local state
|
||||
s.SetAuthToken("")
|
||||
s.SetCurrentUser("")
|
||||
s.SetUsername("")
|
||||
c := s.GetClient().(*api.Client)
|
||||
c.SetToken("")
|
||||
|
||||
display.Println(display.Green, "Logged out")
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/command/debug.go
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/command/game.go
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/command/pass_native.go
|
||||
//go:build !js && !wasm
|
||||
|
||||
package command
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/command/pass_wasm.go
|
||||
//go:build js && wasm
|
||||
|
||||
package command
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/command/registry.go
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/display/board.go
|
||||
package display
|
||||
|
||||
import (
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/display/colors.go
|
||||
package display
|
||||
|
||||
import (
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/display/format.go
|
||||
package display
|
||||
|
||||
import (
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/chess/internal/client/session/session.go
|
||||
package session
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user