Merge pull request #437 from nhost/fix/broadcast-channel-react-native
fix: avoid error when BroadcastChannell is not available
This commit is contained in:
5
.changeset/dirty-trains-pump.md
Normal file
5
.changeset/dirty-trains-pump.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@nhost/core': patch
|
||||
---
|
||||
|
||||
Avoid error when BroadcastChannell is not available
|
||||
@@ -44,13 +44,17 @@ export class AuthClient {
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && autoSignIn) {
|
||||
this._channel = new BroadcastChannel('nhost')
|
||||
this._channel.addEventListener('message', (token) => {
|
||||
const existingToken = this.interpreter?.state.context.refreshToken
|
||||
if (this.interpreter && token.data !== existingToken) {
|
||||
this.interpreter.send({ type: 'TRY_TOKEN', token: token.data })
|
||||
}
|
||||
})
|
||||
try {
|
||||
this._channel = new BroadcastChannel('nhost')
|
||||
this._channel.addEventListener('message', (token) => {
|
||||
const existingToken = this.interpreter?.state.context.refreshToken
|
||||
if (this.interpreter && token.data !== existingToken) {
|
||||
this.interpreter.send({ type: 'TRY_TOKEN', token: token.data })
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
// * BroadcastChannel is not available e.g. react-native
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -659,9 +659,13 @@ export const createAuthMachine = ({
|
||||
// TODO remove the hash. For the moment, it is kept to avoid regression from the current SDK.
|
||||
// * Then, only `refreshToken` will be in the hash, while `type` will be sent by hasura-auth as a query parameter
|
||||
// window.history.pushState({}, '', location.pathname)
|
||||
const channel = new BroadcastChannel('nhost')
|
||||
// ? broadcat session instead of token ?
|
||||
channel.postMessage(refreshToken)
|
||||
try {
|
||||
const channel = new BroadcastChannel('nhost')
|
||||
// ? broadcat session instead of token ?
|
||||
channel.postMessage(refreshToken)
|
||||
} catch (error) {
|
||||
// * BroadcastChannel is not available e.g. react-native
|
||||
}
|
||||
return { session }
|
||||
},
|
||||
importRefreshToken: async () => {
|
||||
|
||||
Reference in New Issue
Block a user