-
Notifications
You must be signed in to change notification settings - Fork 402
feat(vue,nuxt): Add function to dynamically update Clerk options #5235
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
Merged
wobsoriano
merged 9 commits into
main
from
rob/eco-441-expose-function-to-dynamically-update-clerk-options-in-vue
Feb 26, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3e8576e
feat(vue,nuxt): Introduce utility function to dynamically update Cler…
wobsoriano 882314c
chore: Use Clerk from window object
wobsoriano c7f3d69
chore: fix typo
wobsoriano cb8149d
Merge branch 'main' into rob/eco-441-expose-function-to-dynamically-u…
wobsoriano eaeadb0
chore: add test
wobsoriano fdfe379
chore: add changeset
wobsoriano 16c5369
chore: update changeset
wobsoriano 4cc5cc1
chore: make sure window.Clerk is available
wobsoriano bd9f10f
Merge branch 'main' into rob/eco-441-expose-function-to-dynamically-u…
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --- | ||
| "@clerk/nuxt": minor | ||
| "@clerk/vue": minor | ||
| --- | ||
|
|
||
| Introduce `updateClerkOptions()` utility function to update Clerk options on the fly. | ||
|
|
||
| Usage: | ||
|
|
||
| ```vue | ||
| <script setup> | ||
| import { updateClerkOptions } from '@clerk/vue' | ||
| import { dark } from '@clerk/themes' | ||
| import { frFR } from '@clerk/localizations' | ||
|
|
||
| function enableDarkTheme() { | ||
| updateClerkOptions({ | ||
| appearance: { | ||
| baseTheme: dark | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| function changeToFrench() { | ||
| updateClerkOptions({ | ||
| localization: frFR | ||
| }) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <button @click="enableDarkTheme">Enable Dark Theme</button> | ||
| <button @click="changeToFrench">Change to French</button> | ||
| </template> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
integration/templates/vue-vite/src/components/LanguagePicker.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <script setup lang="ts"> | ||
| import { updateClerkOptions } from '@clerk/vue'; | ||
|
|
||
| const onChange = async (event: Event) => { | ||
| const value = (event.target as HTMLSelectElement).value; | ||
| let localization: Record<string, any> | undefined; | ||
|
|
||
| if (value === 'fr') { | ||
| localization = (await import('@clerk/localizations/fr-FR')).frFR; | ||
| } else { | ||
| localization = undefined; | ||
| } | ||
|
|
||
| updateClerkOptions({ | ||
| localization, | ||
| }); | ||
| }; | ||
| </script> | ||
|
|
||
| <template> | ||
| <select @change="onChange"> | ||
| <option value="en">English</option> | ||
| <option value="fr">French</option> | ||
| </select> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export { createRouteMatcher } from './routeMatcher'; | ||
| export { updateClerkOptions } from '@clerk/vue'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './childrenUtils'; | ||
| export * from './toComputedRefs'; | ||
| export * from './useClerkLoaded'; | ||
| export * from './updateClerkOptions'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type { ClerkOptions } from '@clerk/types'; | ||
|
|
||
| type ClerkUpdateOptions = Pick<ClerkOptions, 'appearance' | 'localization'>; | ||
|
|
||
| /** | ||
| * Updates Clerk's options at runtime. | ||
| * | ||
| * @param options - The Clerk options to update | ||
| * | ||
| * @example | ||
| * import { frFR } from '@clerk/localizations'; | ||
| * import { dark } from '@clerk/themes'; | ||
| * | ||
| * updateClerkOptions({ | ||
| * appearance: { baseTheme: dark }, | ||
| * localization: frFR | ||
| * }); | ||
| */ | ||
| export function updateClerkOptions(options: ClerkUpdateOptions) { | ||
| if (!window.Clerk) { | ||
| throw new Error('Missing Clerk instance'); | ||
| } | ||
|
|
||
| // @ts-expect-error - `__unstable__updateProps` is not exposed as public API from `@clerk/types` | ||
| void window.Clerk.__unstable__updateProps({ | ||
| options: { | ||
| localization: options.localization, | ||
| }, | ||
| appearance: options.appearance, | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This will be auto-imported in Nuxt