cjrasmussen / BlueskyApi

Simple helper for interacting with the Bluesky API/AT protocol
MIT License
27 stars 5 forks source link

Fatal error: $apiKey must not be accessed before initialization #10

Closed jaybeaton closed 2 months ago

jaybeaton commented 2 months ago

I set up a process where my code would:

  1. Try to refresh the session with a refresh token.
  2. If that failed, try to start a new session with the handle and password.

I was testing what would happen if a refresh token existed but was invalid and got this error:

Fatal error: Uncaught Error: Typed property cjrasmussen\BlueskyApi\BlueskyApi::$apiKey must not 
be accessed before initialization in vendor/cjrasmussen/bluesky-api/src/BlueskyApi.php:89

The problem is this code in BlueskyApi::refreshSession():

$this->apiKey = $api_key;
$data = $this->request('POST', 'com.atproto.server.refreshSession');
unset($this->apiKey);

Instead of unsetting $apiKey, I think you'll just want to set it back to its initial value of null like this:

$this->apiKey = $api_key;
$data = $this->request('POST', 'com.atproto.server.refreshSession');
$this->apiKey = null;
cjrasmussen commented 2 months ago

You are absolutely correct. This is resolved in v2.0.3. Thanks for the heads-up.