Skip to content

Commit 808efb1

Browse files
fix: change logic
1 parent 958ebdf commit 808efb1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/next-auth/src/react.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,10 @@ export const __NEXTAUTH: AuthClientConfig = {
6767
_getSession: () => {},
6868
}
6969

70+
// https://github.com/nextauthjs/next-auth/pull/10762
7071
let broadcastChannel: BroadcastChannel | null = null
7172

7273
function getNewBroadcastChannel() {
73-
return new BroadcastChannel("next-auth")
74-
}
75-
76-
function broadcast() {
7774
if (typeof BroadcastChannel === "undefined") {
7875
return {
7976
postMessage: () => {},
@@ -82,6 +79,10 @@ function broadcast() {
8279
}
8380
}
8481

82+
return new BroadcastChannel("next-auth")
83+
}
84+
85+
function broadcast() {
8586
if (broadcastChannel === null) {
8687
broadcastChannel = getNewBroadcastChannel()
8788
}
@@ -180,7 +181,8 @@ export async function getSession(params?: GetSessionParams) {
180181
params
181182
)
182183
if (params?.broadcast ?? true) {
183-
broadcast().postMessage({
184+
// https://github.com/nextauthjs/next-auth/pull/11470
185+
getNewBroadcastChannel().postMessage({
184186
event: "session",
185187
data: { trigger: "getSession" },
186188
})

0 commit comments

Comments
 (0)