PAVEE.dev

Site Update (2023-11-05): Minor Bug Fixes

05 November 2023 · Updates

Okay, so there are no updates to the front-facing part of this site. This time, it's concerning the backend dashboard that controls stuff like posts and categories of the posts. It shouldn't affect the front end.

So Uh, What Changed?

Before I tell you that, I just want to tell you a story about the backend of this site first.

I won't be long. Promise.

So, it uses Firebase as the user authentication service. It sucks. I didn't realize you couldn't check the user's authentication state synchronously which is b*llsh*t.

But it's too late now. I didn't want to change it to something else so I stuck with it.

For the longest time, what I did to check the user login state was like this:

async function checkAuthState() {
  const unsubscribe = onAuthStateChanged(auth, (user) => {
    initialized.value = true
  })

  return new Promise<void>((resolve) => {
    const interval = setInterval(() => {
      if (initialized.value) {
        clearInterval(interval)
        unsubscribe()
        resolve()
      }
    }, 50)
  })
}

Really? Really.

It was super dumb.

So How Did I Fix It?

The answer was right there. I just had to use Promise to watch when the state-change before resolving the function. I was too stupid to notice it at the time.

Now, it looks like this:

async function checkAuthState() {
  return new Promise<void>((resolve) => {
    const unsubscribe = onAuthStateChanged(auth, (user) => {
      initialized.value = true
      unsubscribe()
      resolve()
    })
  })
}

It's so, so much better.

Other minor updates:

  • I forgot to set the page meta for each page so the title wasn't updating. It's fixed now.