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
- Initialize Supabase client with custom async storage adapter
- User logs in successfully (session stored)
- User logs out - clear all Supabase keys from storage:
await chrome.storage.local.remove(['sb--auth-token']);
- Reload the page
- 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
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:
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
await chrome.storage.local.remove(['sb--auth-token']);
Expected Behavior:
Actual Behavior:
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
Used Package Manager
npm
Logs
No response
Validations