These days I was using GitHub CodeSpaces to deploy an application to Heroku and I came across a problem: How do I login to Heroku given that I don’t have access to a browser running on the same machine where I’m using the terminal?

If you keep reading this blog post, I will show you exactly how to solve this.

IP mismatch when logging in

You’ve just finished installing Heroku CLI and it’s time to log in. Then you run the following command:

heroku login

This command will give you a page that you can open in your browser and login. Typically you see this page here:

heroku login page

When you click on login, you can log into your account with your traditional method such as username and password, for example, and then your terminal will show that you have logged in successfully.

image login made in the terminal using the browser

It’s kind of magical how this happens, right? However, if you are using GitHub Codespaces, you don’t have a browser to view this login page, and if you try to open that same page using the traditional method of copying the URL and pasting it in your browser, you will find a page with the “IP mismatch” message.

Image showing IP mismatch from heroku

And now what? The secret is to use the iterative way to login from the command line.

Logging into Heroku using the terminal

For cases in which it is not possible to use the browser to see that familiar login screen, the solution is to login interactively. Just use the same command as before followed by the -ioption and then follow the instructions that will show up.

heroku login -i

After running the command above, you will see the user and password request as can be seen in the image below:

Image requesting for the username and password

After entering your data and logging in, you can continue using Heroku via the CLI normally.

Recap

In this post, you learned:

  • How to login to Heroku from GitHub Codespaces.
  • How to resolve the “IP mismatch” error using the -i option when logging into Heroku via the command line.

I hope this post helps you login to Heroku from GitHub Codespaces.