Skip to content

Commit fba3a14

Browse files
authored
fix(react): getSession should update session on current tab (#11470)
1 parent c5163ba commit fba3a14

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/next-auth/src/react.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export const __NEXTAUTH: AuthClientConfig = {
7171

7272
let broadcastChannel: BroadcastChannel | null = null
7373

74+
function getNewBroadcastChannel () {
75+
return new BroadcastChannel("next-auth")
76+
)
77+
7478
function broadcast() {
7579
if (typeof BroadcastChannel === "undefined") {
7680
return {
@@ -81,7 +85,7 @@ function broadcast() {
8185
}
8286

8387
if (broadcastChannel === null) {
84-
broadcastChannel = new BroadcastChannel("next-auth")
88+
broadcastChannel = getNewBroadcastChannel()
8589
}
8690

8791
return broadcastChannel
@@ -178,7 +182,8 @@ export async function getSession(params?: GetSessionParams) {
178182
params
179183
)
180184
if (params?.broadcast ?? true) {
181-
broadcast().postMessage({
185+
const broadcastChannel = getNewBroadcastChannel()
186+
broadcastChannel.postMessage({
182187
event: "session",
183188
data: { trigger: "getSession" },
184189
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy