codingraj's blog

codingraj's blog

When I’m stuck coding, what do I do?

When I’m stuck coding, what do I do?

I get stuck all the time when I’m coding. Actually, I get stuck and look for answers or workarounds online more than I do coding.

codingraj's photo
codingraj
·Aug 28, 2022·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Table of contents

  • When I’m stuck coding, what do I do?

When I’m stuck coding, what do I do?

I get stuck all the time when I’m coding. Actually, I get stuck and look for answers or workarounds online more than I do coding. Probably at a 3:1 ratio of troubleshooting to coding.

Here is an example of me looking for an answer and finding one.

Problem

I’m building an app using Firebase for my authentication. I use Firebase JWTs to ensure the user is logged in and has permission to access the app.

Firebase uses a JSON file containing a secret key for verifying the JWT on my backend server.

I don’t want to put the JSON file containing the secret key in my repository, which is a no-no.

One solution is to put the JSON file as an environmental variable in the .ENV file.

However, the JSON file has some special characters and blank spaces. When I run the code to verify the token, it fails because my code doesn’t read the variable correctly in the .ENV file.

Solution

Google

I googled “firebase auth jwt environment variables.” The first results are from the Firebase Docs. I read the docs but didn’t find the solution.

So I go back to the google results and see some Stackoverflow solutions. I found one solution, but it was rather complex, and some people responded that this solution didn’t work for them.

I just need to be able to read the JSON data from the .ENV file. It got me thinking I should just google how to do that instead of including Firebase. Maybe this will get me more results that will work.

So I googled it again, but with a new search - “how to store JSON in env.” I got a result with a blog titled “How to Store JSON in an Environment Variable.”

This was a perfect solution. It recommended encoding the JSON with base64 and storing that in the .ENV file. And then, in the code, you decode the env variable containing the JSON secret key.

That worked!

Summing it up (TL;DR)

  1. When I run into problems, I do the following:
    1. Google
      1. Search Results
        1. Docs
        2. Stackoverflow
        3. Blogs
 
Share this