workos / authkit-js

Vanilla JS AuthKit SDK
MIT License
9 stars 3 forks source link

Unexpected Error Logging Despite Handled Exceptions #52

Open diegomais opened 4 days ago

diegomais commented 4 days ago

Hello,

I'm encountering an issue with the @workos-inc/authkit-js library where it logs errors to the browser console even though the errors are expected.

image

Specifically, in the code snippet:

https://github.com/workos/authkit-js/blob/5efd97fa980cc33b548171b91049124883e94f98/src/create-client.ts#L108

  async initialize() {
    // [...]
      try {
        await this.#refreshSession();
        this.#scheduleAutomaticRefresh();
      } catch {
        // this is expected to fail if a user doesn't
        // have a session. do nothing.
      }
    }
  }

It seems like errors are being logged despite the comment indicating that the failure to refresh a session is expected and should be silently ignored. Could you please look into this behavior? It would be great to see the error logging suppressed here unless there's a real issue to address.

Thank you!

diegomais commented 4 days ago

Additionally, I've noticed that even without a refresh token, the method authenticateWithRefreshToken() is called, resulting in unnecessary HTTP requests. This behavior seems inefficient and could potentially be avoided if there's no refresh token available.

https://github.com/workos/authkit-js/blob/5efd97fa980cc33b548171b91049124883e94f98/src/create-client.ts#L278C46-L278C74

Could you please also look into this behavior? Optimizing the process to prevent unnecessary requests would be appreciated.

paulfalgout commented 1 day ago

Similarly we're getting hammered with console errors: Error: Missing refresh token. Error: Session has already ended. Error: Session has already ended. But it doesn't seem like there's anything to do to fix these errors, nor that there's any way to supress them.