`platform login` when already logged in
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"?
Hey, thanks for sharing your use case, we'll take this with the team and get back here with potential solutions or a fix.
The command has a -f / --force option, with this intent
The command has a
-f/--forceoption, 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.
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)
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.
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)