-
Notifications
You must be signed in to change notification settings - Fork 402
feat(clerk-js): Add allowedRedirectProtocols #4705
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/types': minor | ||
| --- | ||
|
|
||
| Introduce a new `allowedRedirectProtocols` option to pass additional allowed protocols for user-provided redirect validation. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| export const CLERK_BEFORE_UNLOAD_EVENT = 'clerk:beforeunload'; | ||
|
|
||
| /** | ||
| * Additional protocols can be provided using the `allowedRedirectProtocols` Clerk option. | ||
| */ | ||
| export const ALLOWED_PROTOCOLS = [ | ||
| 'http:', | ||
| 'https:', | ||
|
|
@@ -8,16 +11,13 @@ export const ALLOWED_PROTOCOLS = [ | |
| 'chrome-extension:', | ||
| ]; | ||
|
|
||
| /** | ||
| * Helper utility to navigate via window.location.href. Also dispatches a clerk:beforeunload custom event. | ||
| * | ||
| * Note that this utility should **never** be called with a user-provided URL. We make no specific checks against the contents of the URL here and assume it is safe. Use `Clerk.navigate()` instead for user-provided URLs. | ||
| */ | ||
|
Comment on lines
+17
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we replace the usage for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to, as the url is provided from our API and it will always be external. |
||
| export function windowNavigate(to: URL | string): void { | ||
| let toURL = new URL(to, window.location.href); | ||
|
|
||
| if (!ALLOWED_PROTOCOLS.includes(toURL.protocol)) { | ||
| console.warn( | ||
| `Clerk: "${toURL.protocol}" is not a valid protocol. Redirecting to "/" instead. If you think this is a mistake, please open an issue.`, | ||
| ); | ||
| toURL = new URL('/', window.location.href); | ||
| } | ||
|
|
||
| const toURL = new URL(to, window.location.href); | ||
| window.dispatchEvent(new CustomEvent(CLERK_BEFORE_UNLOAD_EVENT)); | ||
| window.location.href = toURL.href; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.