mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Refactor user onboarding and token management
- Enhanced the `Client` initialization to include `TokenStorage` and configuration parameters. - Replaced `SaveTokenToFile` with a `Client` method for better encapsulation. - Improved onboarding flow with project ID verification and API enablement checks. - Refactored token saving logic to ensure proper handling of directory creation and JSON encoding. - Removed unused file-related code in `auth.go` for improved maintainability.
This commit is contained in:
@@ -33,7 +33,7 @@ func StartService(cfg *config.Config) {
|
||||
}
|
||||
|
||||
if !info.IsDir() && strings.HasSuffix(info.Name(), ".json") {
|
||||
log.Debugf(path)
|
||||
log.Debugf("Loading token from: %s", path)
|
||||
f, errOpen := os.Open(path)
|
||||
if errOpen != nil {
|
||||
return errOpen
|
||||
@@ -56,8 +56,8 @@ func StartService(cfg *config.Config) {
|
||||
log.Info("Authentication successful.")
|
||||
|
||||
// 3. Initialize CLI Client
|
||||
cliClient := client.NewClient(httpClient)
|
||||
if _, err = cliClient.SetupUser(clientCtx, ts.Email, ts.ProjectID, ts.Auto); err != nil {
|
||||
cliClient := client.NewClient(httpClient, &ts, cfg)
|
||||
if _, err = cliClient.SetupUser(clientCtx, ts.Email, ts.ProjectID); err != nil {
|
||||
if err.Error() == "failed to start user onboarding, need define a project id" {
|
||||
log.Error("failed to start user onboarding")
|
||||
project, errGetProjectList := cliClient.GetProjectList(clientCtx)
|
||||
|
||||
Reference in New Issue
Block a user