cli icon indicating copy to clipboard operation
cli copied to clipboard

`platform login` when already logged in

Open cs278 opened this issue 1 year ago • 6 comments

I'd be useful if the login command supported someway of telling it to do nothing if I'm already logged in, I want to call it at the start of scripts that talk to Platform to ensure the user is logged in but it doesn't need to ask them if they want to login again. I've tried platform login --{no-interaction,no,yes} but these tell the command doesn't work non interactively. platform login --quiet doesn't work either as it just silently does nothing.

Could some other argument like --if-already-logged-in-dont-nag-the-user be added to turn off the "you're already logged in prompt"?

cs278 avatar Jul 04 '24 09:07 cs278

Hey, thanks for sharing your use case, we'll take this with the team and get back here with potential solutions or a fix.

akalipetis avatar Jul 04 '24 11:07 akalipetis

The command has a -f / --force option, with this intent

pjcdawkins avatar Jul 18 '24 13:07 pjcdawkins

The command has a -f / --force option, with this intent

That appears to force me through the login process again which makes sense to me. I don't want to have to login everytime I run a script.

cs278 avatar Jul 18 '24 14:07 cs278

Ah I see.

Currently each command is supposed to prompt the user to log in when necessary.

There is a possibility auth:info could help:

email=$(platform auth:info --no-auto-login email)
if [ -n "$email" ]; then
  echo "Logged in as $email"
else
  echo "Not logged in"
  exit 1
fi

(Or if it's an unattended script, perhaps you need an API token)

pjcdawkins avatar Jul 18 '24 18:07 pjcdawkins

Currently each command is supposed to prompt the user to log in when necessary.

That it does, but I find if the first call to platform is inside some shell structures all hell breaks loose - I don't know if that's down to a bug in the CLI or just how it should work. As a result I started adding platform login to the start of all my scripts, but now I get the nag asking me if I want to login again if I have already authed.

cs278 avatar Jul 18 '24 20:07 cs278

Fair enough, I'd be glad to help if I can with the hell breaking loose, here or you could perhaps ask me on chat.platform.sh.

For a login check, we need to perform some kind of API call - although we can check offline whether you have credentials saved, the session could still have been revoked or expired for a few different reasons.

Something like this would perform that API call and prompt for login if necessary at the top of your script.

email=$(platform auth:info --refresh email)

pjcdawkins avatar Jul 19 '24 08:07 pjcdawkins