Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

platform login when already logged in #191

Open
cs278 opened this issue Jul 4, 2024 · 6 comments
Open

platform login when already logged in #191

cs278 opened this issue Jul 4, 2024 · 6 comments
Labels

Comments

@cs278
Copy link

cs278 commented Jul 4, 2024

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"?

Copy link
Member

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

@linear linear bot added the Auth label Jul 18, 2024
@pjcdawkins
Copy link
Contributor

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

@cs278
Copy link
Author

cs278 commented Jul 18, 2024

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.

@pjcdawkins
Copy link
Contributor

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)

@cs278
Copy link
Author

cs278 commented Jul 18, 2024

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.

@pjcdawkins
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants