-
Notifications
You must be signed in to change notification settings - Fork 253
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
feat(clerk-js): Sign Out from multiple tabs at once #2094
feat(clerk-js): Sign Out from multiple tabs at once #2094
Conversation
🦋 Changeset detectedLatest commit: 3391990 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
2f0d78b
to
1601f5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good candidate for adding a test to our suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome back LocalStorageBroadcastChannel :)
packages/clerk-js/src/core/clerk.ts
Outdated
@@ -1530,7 +1531,7 @@ export default class Clerk implements ClerkInterface { | |||
|
|||
this.#broadcastChannel?.addEventListener('message', ({ data }) => { | |||
if (data.type === 'signout') { | |||
void this.handleUnauthenticated({ broadcast: false }); | |||
void this.handleUnauthenticated({ broadcast: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's necessary to have broadcast to default to enable post the sign-out message to the BroadcastChannel, but it's not necessary to fill the this. handleUnauthenticated
as broadcast
prop is always true.
@octoper good job on this! I've approved as I don't want to block, but this is the perfect case for an e2e test. Let's write one before merging. |
@nikosdouvlis Already on it's way! |
1601f5d
to
e334c0a
Compare
da6936f
to
4294999
Compare
ec2e590
to
d017be1
Compare
}); | ||
}); | ||
|
||
expect(await mainTab.page.evaluate('!window.Clerk.user')).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃 let's add a await m.po.expect.toBeSignedOut();
test helper and use it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper exists but there is a problem with it, the page.waitFucntion
that is underneath mainTab.po.expect.toBeSignedOut()
helper is getting a timeout at this point, I'm not exactly sure why is that, but it's probably has something to do with with the new tab we are opening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a comment about why we cannot use the helper and fix this later.
e883e80
to
93278c7
Compare
93278c7
to
3391990
Compare
await m.po.expect.toBeSignedOut(); | ||
}); | ||
|
||
expect(await mainTab.page.evaluate('!window.Clerk.user')).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ shouldn't this be toBe(true)
? If we're trying to replicate toBeSignedOut()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right! Just opened a PR for that #2125
Description
This PR enables the BrodcastChannel functionallity, that is going to allow us to signout from multiple tabs at once.
Checklist
npm test
runs as expected.npm run build
runs as expected.Type of change
Packages affected
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/clerk-expo
@clerk/fastify
gatsby-plugin-clerk
@clerk/localizations
@clerk/nextjs
@clerk/clerk-react
@clerk/remix
@clerk/clerk-sdk-node
@clerk/shared
@clerk/themes
@clerk/types
build/tooling/chore