Skip to content

createClient throws during _initSupabaseAuthClient when storage is empty/freshly cleared #2030

@sat008sat

Description

@sat008sat

Describe the bug

When using a custom async storage adapter (for Chrome extension with chrome.storage.local), the Supabase client crashes during initialization if the storage was recently cleared (e.g., after logout).

Instead of gracefully handling empty storage as "no session," the library throws an uncaught error in _initSupabaseAuthClient.

Environment:

  • @supabase/supabase-js version: 2.x (bundled)
  • Environment: Chrome Extension (Manifest V3)
  • Storage adapter: Custom async adapter using chrome.storage.local

Custom Storage Adapter:
const chromeStorageAdapter = {
getItem: async (key) => {
return new Promise((resolve) => {
chrome.storage.local.get([key], (result) => {
resolve(result[key] ?? null);
});
});
},
setItem: async (key, value) => {
return new Promise((resolve, reject) => {
chrome.storage.local.set({ [key]: value }, resolve);
});
},
removeItem: async (key) => {
return new Promise((resolve) => {
chrome.storage.local.remove([key], resolve);
});
}
};

Library affected

supabase-js

Reproduction

No response

Steps to reproduce

  1. Initialize Supabase client with custom async storage adapter
  2. User logs in successfully (session stored)
  3. User logs out - clear all Supabase keys from storage:
    await chrome.storage.local.remove(['sb--auth-token']);
  4. Reload the page
  5. Call createClient() again

Expected Behavior:

  • createClient() should initialize successfully
  • getSession() should return null (no session)
  • App can show login screen

Actual Behavior:

  • createClient() throws an error during _initSupabaseAuthClient
  • App crashes

Error Stack Trace:
Uncaught (in promise) Error
at e (supabase.min.js:7)
at Fr (supabase.min.js:7)
at _initSupabaseAuthClient (supabase.min.js:7)
at Jr (supabase.min.js:7)
at e.createClient (supabase.min.js:7)

Workaround:
We wrapped createClient() in a try-catch and return null on failure, treating it as "not logged in":
function initSupabase() {
try {
return supabase.createClient(URL, KEY, {
auth: { storage: chromeStorageAdapter }
});
} catch (error) {
console.error('Supabase init failed:', error);
return null;
}
}

Suggested Fix:
The auth client initialization should handle empty/missing storage gracefully, treating it as "no existing session" rather than throwing an error.

System Info

OS: macOS (Darwin 25.0.0)
  Browser: Chrome (latest)
  Environment: Chrome Extension (Manifest V3)
  Node: N/A (browser-only)

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsupabase-jsRelated to the supabase-js library.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions