mirror of
https://lavaforge.org/spotizerr/spotizerr-auth.git
synced 2025-12-23 18:29:16 -05:00
Added support for reusing pre-existing credentials.json file
This commit is contained in:
@@ -356,10 +356,27 @@ def main():
|
|||||||
cred_file = pathlib.Path("credentials.json")
|
cred_file = pathlib.Path("credentials.json")
|
||||||
if cred_file.exists():
|
if cred_file.exists():
|
||||||
console.print(f"⚠️ [yellow]'{cred_file}' already exists.[/]")
|
console.print(f"⚠️ [yellow]'{cred_file}' already exists.[/]")
|
||||||
if Confirm.ask("Overwrite it by connecting to Spotify?", default=True):
|
# Validate existing credentials before offering reuse
|
||||||
get_spotify_session_and_wait_for_credentials()
|
can_reuse = False
|
||||||
|
try:
|
||||||
|
if cred_file.stat().st_size > 0:
|
||||||
|
with open(cred_file, "r") as f:
|
||||||
|
_existing = json.load(f)
|
||||||
|
can_reuse = isinstance(_existing, dict) and len(_existing) > 0
|
||||||
|
except Exception:
|
||||||
|
can_reuse = False
|
||||||
|
if can_reuse:
|
||||||
|
if Confirm.ask("Reuse existing 'credentials.json' without reconnecting to Spotify?", default=True):
|
||||||
|
console.print(f"{Icons.INFO} Using existing 'credentials.json'.")
|
||||||
|
else:
|
||||||
|
get_spotify_session_and_wait_for_credentials()
|
||||||
else:
|
else:
|
||||||
console.print(f"{Icons.INFO} Using existing 'credentials.json'.")
|
console.print("❌ [bold red]Existing 'credentials.json' is invalid or empty. You must reconnect to Spotify.[/]")
|
||||||
|
if Confirm.ask("Connect now to create a fresh 'credentials.json'?", default=True):
|
||||||
|
get_spotify_session_and_wait_for_credentials()
|
||||||
|
else:
|
||||||
|
console.print("❌ [bold red]Cannot continue without a valid 'credentials.json'. Exiting.[/]")
|
||||||
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
get_spotify_session_and_wait_for_credentials()
|
get_spotify_session_and_wait_for_credentials()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user