Skip to content

fix: always check typeof BroadcastChannel #12937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/next-auth/src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ export const __NEXTAUTH: AuthClientConfig = {
_getSession: () => {},
}

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

function getNewBroadcastChannel() {
return new BroadcastChannel("next-auth")
}

function broadcast() {
if (typeof BroadcastChannel === "undefined") {
return {
postMessage: () => {},
Expand All @@ -82,6 +79,10 @@ function broadcast() {
}
}

return new BroadcastChannel("next-auth")
}

function broadcast() {
if (broadcastChannel === null) {
broadcastChannel = getNewBroadcastChannel()
}
Expand Down Expand Up @@ -180,8 +181,8 @@ export async function getSession(params?: GetSessionParams) {
params
)
if (params?.broadcast ?? true) {
const broadcastChannel = getNewBroadcastChannel()
broadcastChannel.postMessage({
// https://github.com/nextauthjs/next-auth/pull/11470
getNewBroadcastChannel().postMessage({
event: "session",
data: { trigger: "getSession" },
})
Expand Down
Loading