Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions src/cli/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,40 @@ import (
"fmt"
"os"

"github.com/devhindo/x/src/cli/lock"
"github.com/devhindo/x/src/cli/config"
)

// func check_authentication() {}

func Auth() {
cfg, err := config.LoadConfig()
if err != nil {
fmt.Println("Error loading config:", err)
os.Exit(1)
}

checkIfUserExists()
if len(cfg.Apps) == 0 {
fmt.Println("No apps found. Run 'x init add' first.")
os.Exit(1)
}

u := newUser()
u.add_user_to_db()
u.open_browser_to_auth_url()
fmt.Println("please authorize X CLI in your browser then run 'x auth --verify'")
fmt.Println("if the browser does not open, run 'x auth --url` to get the authorization url")
}
app := cfg.GetActiveApp()
if app == nil {
// Fallback to first app if active not set
if len(cfg.Apps) > 0 {
app = &cfg.Apps[0]
cfg.ActiveApp = app.Name
config.SaveConfig(cfg)
} else {
fmt.Println("No apps found. Run 'x init add' first.")
os.Exit(1)
}
}

func checkIfUserExists() {
_, err := lock.ReadLicenseKeyFromFile()
if err == nil {
fmt.Println("a user is already logged in | try 'x -h'")
os.Exit(0)
fmt.Printf("Authenticating app '%s'...\n", app.Name)
err = StartAuthFlow(app)
if err != nil {
fmt.Println("Authentication failed:", err)
os.Exit(1)
}

fmt.Println("Authentication successful! You can now use 'x tweet'.")
}
59 changes: 0 additions & 59 deletions src/cli/auth/crud.go

This file was deleted.

21 changes: 0 additions & 21 deletions src/cli/auth/geturl.go

This file was deleted.

30 changes: 0 additions & 30 deletions src/cli/auth/license.go

This file was deleted.

18 changes: 0 additions & 18 deletions src/cli/auth/lock.go

This file was deleted.

Loading
Loading