Skip to content

Commit 11d7239

Browse files
committed
fix: ensure chrome runtime message listener is added and removed safely
1 parent 5328619 commit 11d7239

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/providers/AuthProvider.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
6969
}
7070
}
7171

72-
chrome?.runtime?.onMessage.addListener(messageListener)
72+
if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.onMessage) {
73+
chrome.runtime.onMessage.addListener(messageListener)
74+
}
7375

7476
return () => {
75-
chrome?.runtime?.onMessage.removeListener(messageListener)
77+
if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.onMessage) {
78+
chrome.runtime.onMessage.removeListener(messageListener)
79+
}
7680
}
7781
}, [])
7882

@@ -85,6 +89,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
8589
const provider = searchParams.get('provider')
8690
connectTheUser(token, provider).catch((error) => {
8791
openAuthModal()
92+
console.log('error', error)
8893
if (error && error.code === 'auth/account-exists-with-different-credential') {
8994
setAuthError({
9095
message:

0 commit comments

Comments
 (0)