From 013d28c70d15cc0d168697364928fa259a3f4ac6 Mon Sep 17 00:00:00 2001 From: Alexis Aguilar <98043211+alexisintech@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:36:04 -0400 Subject: [PATCH] chore: combine 'index.html' and 'main.js' using (#1603) Co-authored-by: victoria --- docs/advanced-usage/using-proxies.mdx | 2 +- .../authentication/google-one-tap.mdx | 6 +- docs/components/authentication/sign-in.mdx | 8 +- docs/components/authentication/sign-up.mdx | 8 +- .../organization/create-organization.mdx | 8 +- .../organization/organization-list.mdx | 4 +- .../organization/organization-profile.mdx | 8 +- .../organization/organization-switcher.mdx | 4 +- docs/components/user/user-button.mdx | 4 +- docs/components/user/user-profile.mdx | 8 +- docs/custom-flows/email-sms-otp.mdx | 4 +- docs/custom-flows/error-handling.mdx | 202 ++++----- docs/custom-flows/invitations.mdx | 2 +- docs/customization/organization-profile.mdx | 2 +- docs/customization/user-profile.mdx | 2 +- docs/quickstarts/javascript.mdx | 2 +- .../javascript/clerk/organization-methods.mdx | 4 +- .../javascript/organization-invitation.mdx | 2 +- .../javascript/organization/domains.mdx | 6 +- .../javascript/organization/invitations.mdx | 6 +- .../javascript/organization/members.mdx | 384 +++++++++--------- .../organization/membership-request.mdx | 300 +++++++------- .../javascript/organization/organization.mdx | 124 +++--- docs/references/javascript/session.mdx | 2 +- .../javascript/user/create-metadata.mdx | 126 +++--- .../javascript/user/password-management.mdx | 118 +++--- docs/references/javascript/user/totp.mdx | 240 +++++------ docs/references/javascript/user/user.mdx | 116 +++--- docs/users/metadata.mdx | 2 +- 29 files changed, 852 insertions(+), 852 deletions(-) diff --git a/docs/advanced-usage/using-proxies.mdx b/docs/advanced-usage/using-proxies.mdx index 8c5d3cd26e..dff1261dc1 100644 --- a/docs/advanced-usage/using-proxies.mdx +++ b/docs/advanced-usage/using-proxies.mdx @@ -285,7 +285,7 @@ When using a proxy, all requests to the Frontend API will be made through your d To configure your proxy setup using properties in your JavaScript application, pass the `proxyUrl` option to the [`load()`](/docs/references/javascript/clerk/clerk#load) method. - "]}> + "]}> ```js {{ filename: 'main.js' }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/authentication/google-one-tap.mdx b/docs/components/authentication/google-one-tap.mdx index 94a36ed34f..0f7bdc2763 100644 --- a/docs/components/authentication/google-one-tap.mdx +++ b/docs/components/authentication/google-one-tap.mdx @@ -112,7 +112,7 @@ function openGoogleOneTap(params: GoogleOneTapProps): void #### `openGoogleOneTap()` usage -']}> +']}> ```js {{ filename: 'index.js', mark: [[7, 12]] }} import { Clerk } from '@clerk/clerk-js' @@ -163,7 +163,7 @@ function closeGoogleOneTap(): void #### `closeGoogleOneTap()` usage -']}> +']}> ```js {{ filename: 'index.js', mark: [16] }} import { Clerk } from '@clerk/clerk-js' @@ -236,7 +236,7 @@ function authenticateWithGoogleOneTap( #### `authenticateWithGoogleOneTap()` usage -']}> +']}> ```js {{ filename: 'index.js', mark: [[7, 15]] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/authentication/sign-in.mdx b/docs/components/authentication/sign-in.mdx index 912cff18a0..aec18bd4a8 100644 --- a/docs/components/authentication/sign-in.mdx +++ b/docs/components/authentication/sign-in.mdx @@ -182,7 +182,7 @@ function mountSignIn(node: HTMLDivElement, props?: SignInProps): void #### `mountSignIn()` usage -']}> +']}> ```js {{ filename: 'index.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -244,7 +244,7 @@ function unmountSignIn(node: HTMLDivElement): void #### `unmountSignIn()` usage -']}> +']}> ```js {{ filename: 'index.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' @@ -314,7 +314,7 @@ function openSignIn(props?: SignInProps): void #### `openSignIn()` usage -']}> +']}> ```js {{ filename: 'index.js', mark: [7] }} import { Clerk } from '@clerk/clerk-js' @@ -356,7 +356,7 @@ function closeSignIn(): void #### `closeSignIn()` usage -']}> +']}> ```js {{ filename: 'index.js', mark: [11] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/authentication/sign-up.mdx b/docs/components/authentication/sign-up.mdx index 2936ac73ee..92ebff93f5 100644 --- a/docs/components/authentication/sign-up.mdx +++ b/docs/components/authentication/sign-up.mdx @@ -175,7 +175,7 @@ function mountSignUp(node: HTMLDivElement, props?: SignUpProps): void #### `mountSignUp()` usage -']}> +']}> ```typescript {{ filename: 'index.ts', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -237,7 +237,7 @@ function unmountSignUp(node: HTMLDivElement): void #### `unmountSignUp()` usage -']}> +']}> ```typescript {{ filename: 'index.ts', mark: [17] }} import { Clerk } from '@clerk/clerk-js' @@ -307,7 +307,7 @@ function openSignUp(props?: SignUpProps): void #### `openSignUp()` usage -']}> +']}> ```js {{ filename: 'index.ts', mark: [7] }} import { Clerk } from '@clerk/clerk-js' @@ -349,7 +349,7 @@ function closeSignUp(): void #### `closeSignUp()` usage -']}> +']}> ```js {{ filename: 'index.ts', mark: [11] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/organization/create-organization.mdx b/docs/components/organization/create-organization.mdx index 8e6c125c3a..08d2795a37 100644 --- a/docs/components/organization/create-organization.mdx +++ b/docs/components/organization/create-organization.mdx @@ -146,7 +146,7 @@ function mountCreateOrganization(node: HTMLDivElement, props?: CreateOrganizatio #### `mountCreateOrganization()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -208,7 +208,7 @@ function unmountCreateOrganization(node: HTMLDivElement): void #### `unmountCreateOrganization()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' @@ -278,7 +278,7 @@ function openCreateOrganization(props?: CreateOrganizationProps): void #### `openCreateOrganization()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -331,7 +331,7 @@ function closeCreateOrganization(): void #### `closeCreateOrganization()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/organization/organization-list.mdx b/docs/components/organization/organization-list.mdx index d476316d13..d97d133011 100644 --- a/docs/components/organization/organization-list.mdx +++ b/docs/components/organization/organization-list.mdx @@ -177,7 +177,7 @@ function mountOrganizationList(node: HTMLDivElement, props?: OrganizationListPro ### `mountOrganizationList()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -239,7 +239,7 @@ function unmountOrganizationList(node: HTMLDivElement): void ### `unmountOrganizationList()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/organization/organization-profile.mdx b/docs/components/organization/organization-profile.mdx index e67d22e72c..93e0731b7d 100644 --- a/docs/components/organization/organization-profile.mdx +++ b/docs/components/organization/organization-profile.mdx @@ -143,7 +143,7 @@ function mountOrganizationProfile(node: HTMLDivElement, props?: OrganizationProf #### `mountOrganizationProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -205,7 +205,7 @@ function unmountOrganizationProfile(node: HTMLDivElement): void #### `unmountOrganizationProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' @@ -275,7 +275,7 @@ function openOrganizationProfile(props?: OrganizationProfileProps): void #### `openOrganizationProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -328,7 +328,7 @@ function closeOrganizationProfile(): void #### `closeOrganizationProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/organization/organization-switcher.mdx b/docs/components/organization/organization-switcher.mdx index 3f1ca25376..f7e6a378ee 100644 --- a/docs/components/organization/organization-switcher.mdx +++ b/docs/components/organization/organization-switcher.mdx @@ -204,7 +204,7 @@ function mountOrganizationSwitcher(node: HTMLDivElement, props?: OrganizationSwi ### mountOrganizationSwitcher() usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -266,7 +266,7 @@ function unmountOrganizationSwitcher(node: HTMLDivElement): void ### unmountOrganizationSwitcher() usage -']}> +']}> ```js {{ filename: 'main.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/user/user-button.mdx b/docs/components/user/user-button.mdx index 41816a0ea0..76029970cb 100644 --- a/docs/components/user/user-button.mdx +++ b/docs/components/user/user-button.mdx @@ -284,7 +284,7 @@ function mountUserButton(node: HTMLDivElement, props?: UserButtonProps): void #### `mountUserButton()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -346,7 +346,7 @@ function unmountUserButton(node: HTMLDivElement): void #### `unmountUserButton()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/components/user/user-profile.mdx b/docs/components/user/user-profile.mdx index c2ec3931fa..4c72998229 100644 --- a/docs/components/user/user-profile.mdx +++ b/docs/components/user/user-profile.mdx @@ -139,7 +139,7 @@ function mountUserProfile(node: HTMLDivElement, props?: UserProfileProps): void #### `mountUserProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -201,7 +201,7 @@ function unmountUserProfile(node: HTMLDivElement): void #### `unmountUserProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [17] }} import { Clerk } from '@clerk/clerk-js' @@ -271,7 +271,7 @@ function openUserProfile(props?: UserProfileProps): void #### `openUserProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' @@ -324,7 +324,7 @@ function closeUserProfile(): void #### `closeUserProfile()` usage -']}> +']}> ```js {{ filename: 'main.js', mark: [13] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/custom-flows/email-sms-otp.mdx b/docs/custom-flows/email-sms-otp.mdx index ca7821d7dc..d9b2e47306 100644 --- a/docs/custom-flows/email-sms-otp.mdx +++ b/docs/custom-flows/email-sms-otp.mdx @@ -136,7 +136,7 @@ This guide will walk you through how to build a custom SMS OTP sign-up and sign- - "]}> + "]}> Use the following tabs to view the code necessary for each file. @@ -542,7 +542,7 @@ This guide will walk you through how to build a custom SMS OTP sign-up and sign- - "]}> + "]}> Use the following tabs to view the code necessary for each file. diff --git a/docs/custom-flows/error-handling.mdx b/docs/custom-flows/error-handling.mdx index fccb0c2d93..81b08db8e2 100644 --- a/docs/custom-flows/error-handling.mdx +++ b/docs/custom-flows/error-handling.mdx @@ -114,111 +114,111 @@ The following example uses the [email & password sign-in custom flow](/docs/cust "]}> - For the following example, your HTML file should look like this: - - ```html {{ filename: 'index.html' }} - - - - - - Clerk + JavaScript App - - -
- -
-

Sign up

-
- - - - - + Use the following tabs to view the code necessary for each file. + + + ```html {{ filename: 'index.html' }} + + + + + + Clerk + JavaScript App + + +
+ +
+

Sign up

+ + + + + + + +
+ + -
- - -

- - - - - ``` - - And your JavaScript file should look like this: - - ```js {{ filename: 'main.js' }} - import Clerk from '@clerk/clerk-js' - - // Initialize Clerk with your Clerk publishable key - const clerk = new Clerk('{{pub_key}}') - await clerk.load() - - if (clerk.user) { - // Mount user button component - document.getElementById('signed-in').innerHTML = ` -
- ` - - const userbuttonDiv = document.getElementById('user-button') - - clerk.mountUserButton(userbuttonDiv) - } else { - // Handle the sign-up form - document.getElementById('sign-up-form').addEventListener('submit', async (e) => { - e.preventDefault() - - const formData = new FormData(e.target) - const emailAddress = formData.get('email') - const password = formData.get('password') - - try { - // Start the sign-up process using the phone number method - await clerk.client.signUp.create({ emailAddress, password }) - await clerk.client.signUp.prepareEmailAddressVerification() - // Hide sign-up form - document.getElementById('sign-up').setAttribute('hidden', '') - // Show verification form - document.getElementById('verifying').removeAttribute('hidden') - } catch (err) { - if (isClerkAPIResponseError(err)) { - const errors = err.errors - document.getElementById('error').textContent = errors[0].longMessage +

+ + + + + ``` + + ```js {{ filename: 'main.js' }} + import Clerk from '@clerk/clerk-js' + + // Initialize Clerk with your Clerk publishable key + const clerk = new Clerk('{{pub_key}}') + await clerk.load() + + if (clerk.user) { + // Mount user button component + document.getElementById('signed-in').innerHTML = ` +
+ ` + + const userbuttonDiv = document.getElementById('user-button') + + clerk.mountUserButton(userbuttonDiv) + } else { + // Handle the sign-up form + document.getElementById('sign-up-form').addEventListener('submit', async (e) => { + e.preventDefault() + + const formData = new FormData(e.target) + const emailAddress = formData.get('email') + const password = formData.get('password') + + try { + // Start the sign-up process using the phone number method + await clerk.client.signUp.create({ emailAddress, password }) + await clerk.client.signUp.prepareEmailAddressVerification() + // Hide sign-up form + document.getElementById('sign-up').setAttribute('hidden', '') + // Show verification form + document.getElementById('verifying').removeAttribute('hidden') + } catch (err) { + if (isClerkAPIResponseError(err)) { + const errors = err.errors + document.getElementById('error').textContent = errors[0].longMessage + } + console.error(JSON.stringify(err, null, 2)) } - console.error(JSON.stringify(err, null, 2)) - } - }) - - // Handle the verification form - document.getElementById('verifying').addEventListener('submit', async (e) => { - const formData = new FormData(e.target) - const code = formData.get('code') - - try { - // Verify the phone number - const verify = await clerk.client.signUp.attemptEmailAddressVerification({ - code, - }) - - // Now that the user is created, set the session to active. - await clerk.setActive({ session: verify.createdSessionId }) - } catch (err) { - if (isClerkAPIResponseError(err)) { - const errors = err.errors - document.getElementById('error').textContent = errors[0].longMessage + }) + + // Handle the verification form + document.getElementById('verifying').addEventListener('submit', async (e) => { + const formData = new FormData(e.target) + const code = formData.get('code') + + try { + // Verify the phone number + const verify = await clerk.client.signUp.attemptEmailAddressVerification({ + code, + }) + + // Now that the user is created, set the session to active. + await clerk.setActive({ session: verify.createdSessionId }) + } catch (err) { + if (isClerkAPIResponseError(err)) { + const errors = err.errors + document.getElementById('error').textContent = errors[0].longMessage + } + console.error(JSON.stringify(err, null, 2)) } - console.error(JSON.stringify(err, null, 2)) - } - }) - } - ``` + }) + } + ``` +
diff --git a/docs/custom-flows/invitations.mdx b/docs/custom-flows/invitations.mdx index dd578bf306..e911df6ad2 100644 --- a/docs/custom-flows/invitations.mdx +++ b/docs/custom-flows/invitations.mdx @@ -132,7 +132,7 @@ To create a sign-up flow using the invitation token, you need to extract the tok - "]}> + "]}> ```html {{ filename: 'index.html' }} diff --git a/docs/customization/organization-profile.mdx b/docs/customization/organization-profile.mdx index e7c61bc059..9e648c1698 100644 --- a/docs/customization/organization-profile.mdx +++ b/docs/customization/organization-profile.mdx @@ -164,7 +164,7 @@ The following example demonstrates two ways that you can render content in the ` To add custom pages to the `` component using the [JavaScript SDK](/docs/references/javascript/overview), you can pass the `customPages` property to the `mountOrganizationProfile()` or `openOrganizationProfile()` method, as shown in the following example: -']}> +']}> ```js {{ filename: 'main.js' }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/customization/user-profile.mdx b/docs/customization/user-profile.mdx index 5799f42d84..cab1ceafcb 100644 --- a/docs/customization/user-profile.mdx +++ b/docs/customization/user-profile.mdx @@ -210,7 +210,7 @@ The following example demonstrates two ways that you can render content in the ` To add custom pages to the `` component using the [JavaScript SDK](/docs/references/javascript/overview), you can pass the `customPages` property to the `mountUserProfile()` or `openUserProfile()` method, as shown in the following example: -']}> +']}> ```js {{ filename: 'main.js' }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/quickstarts/javascript.mdx b/docs/quickstarts/javascript.mdx index 52945c68dc..6e4c4385b1 100644 --- a/docs/quickstarts/javascript.mdx +++ b/docs/quickstarts/javascript.mdx @@ -31,7 +31,7 @@ To add the [ClerkJS SDK](/docs/references/javascript/overview) to your JavaScrip Select your preferred method below to get started. -"]}> +"]}> { /* NPM module tab */} diff --git a/docs/references/javascript/clerk/organization-methods.mdx b/docs/references/javascript/clerk/organization-methods.mdx index 72a43f4978..b82b5eb80d 100644 --- a/docs/references/javascript/clerk/organization-methods.mdx +++ b/docs/references/javascript/clerk/organization-methods.mdx @@ -31,7 +31,7 @@ function getOrganization(organizationId: string): Promise']}> +']}> ```js {{ filename: 'main.js', mark: [9, 10] }} @@ -165,7 +165,7 @@ function createOrganization({ name, slug }: CreateOrganizationParams): Promise']}> +']}> ```js {{ filename: 'main.js', mark: [[10, 13]] }} diff --git a/docs/references/javascript/organization-invitation.mdx b/docs/references/javascript/organization-invitation.mdx index 2ce5ccc3c2..54d33bc17a 100644 --- a/docs/references/javascript/organization-invitation.mdx +++ b/docs/references/javascript/organization-invitation.mdx @@ -86,7 +86,7 @@ It assumes: - you have followed the [quickstart](/docs/quickstarts/javascript) in order to add Clerk to your JavaScript application - you have [enabled the Organizations feature in your Clerk Dashboard](/docs/organizations/overview#enable-organizations-in-your-application) -']}> +']}> ```js {{ filename: 'main.js', mark: [21, 22] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/references/javascript/organization/domains.mdx b/docs/references/javascript/organization/domains.mdx index 00669373c9..4273c78320 100644 --- a/docs/references/javascript/organization/domains.mdx +++ b/docs/references/javascript/organization/domains.mdx @@ -36,7 +36,7 @@ function createDomain(domainName: string): Promise ### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [10, 11] }} import { Clerk } from '@clerk/clerk-js' @@ -163,7 +163,7 @@ function getDomains(params?: GetDomainsParams): Promise']}> +']}> ```js {{ filename: 'main.js', mark: [10, 11] }} import { Clerk } from '@clerk/clerk-js' @@ -276,7 +276,7 @@ function getDomain(params: GetDomainParams): Promise ### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [12, 13] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/references/javascript/organization/invitations.mdx b/docs/references/javascript/organization/invitations.mdx index 3e7ce8dbdd..32b83247e7 100644 --- a/docs/references/javascript/organization/invitations.mdx +++ b/docs/references/javascript/organization/invitations.mdx @@ -51,7 +51,7 @@ function getInvitations( ### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [10, 11] }} import { Clerk } from '@clerk/clerk-js' @@ -173,7 +173,7 @@ function inviteMember(params: InviteMemberParams): Promise']}> +']}> ```js {{ filename: 'main.js', mark: [13, 14] }} import { Clerk } from '@clerk/clerk-js' @@ -301,7 +301,7 @@ function inviteMembers(params: InviteMembersParams): Promise']}> +']}> ```js {{ filename: 'main.js', mark: [13, 14] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/references/javascript/organization/members.mdx b/docs/references/javascript/organization/members.mdx index c7e5b3a29b..5d2db0cb30 100644 --- a/docs/references/javascript/organization/members.mdx +++ b/docs/references/javascript/organization/members.mdx @@ -142,219 +142,219 @@ function removeMember(userId: string): Promise The following example demonstrates how to use the organization membership methods to manage the members of an organization. To ease the development process, the response or error message of a method will be displayed on the user interface. -']}> +']}> - For the following example, your HTML file should look like this: + Use the following tabs to view the code necessary for each file. + + + ```html {{ filename: 'index.html' }} + + + + + + + Clerk + JavaScript App + + + +
+ + + +

Memberships List

+ + + + + + + + + + + +
User IDIdentifierRole
+ +
+

Add member

+ + +
+ +

Response:

+

+
+          
+        
+      
+      ```
+
+      ```js {{ filename: 'main.js', mark: [13, 41, 58, 75] }}
+      import { Clerk } from '@clerk/clerk-js'
+
+      // Initialize Clerk with your Clerk publishable key
+      const clerk = new Clerk('{{pub_key}}')
+      await clerk.load()
+
+      if (clerk.user) {
+        // Check for an active organization
+        if (clerk.organization) {
+          // Render list of organization memberships
+          async function renderMemberships(organization, isAdmin) {
+            try {
+              const { data } = await organization.getMemberships()
+
+              const memberships = data
+              console.log(`getMemberships:`, memberships)
+
+              memberships.map((membership) => {
+                const membershipTable = document.getElementById('memberships_table')
+                const row = membershipTable.insertRow()
+                row.insertCell().textContent = membership.publicUserData.userId
+                row.insertCell().textContent = membership.publicUserData.identifier
+                row.insertCell().textContent = membership.role
+
+                // Add administrative actions:
+                // Add and remove a member, and update a member's role.
+                if (isAdmin) {
+                  // Show add, update, remove member buttons
+                  document.getElementById('add-member-container').removeAttribute('hidden')
+                  document.getElementById('update-role-head').removeAttribute('hidden')
+                  document.getElementById('remove-member-head').removeAttribute('hidden')
+
+                  // Get the user ID of the member
+                  const userId = membership.publicUserData.userId
+
+                  // Update a member's role
+                  const updateBtn = document.createElement('button')
+                  updateBtn.textContent = 'Change role'
+                  updateBtn.addEventListener('click', async function (e) {
+                    e.preventDefault()
+                    const role = membership.role === 'org:admin' ? 'org:member' : 'org:admin'
+                    await organization
+                      .updateMember({ userId, role })
+                      .then((res) => {
+                        document.getElementById('response').innerHTML = JSON.stringify(res)
+                      })
+                      .catch((error) => {
+                        document.getElementById('error-container').removeAttribute('hidden')
+                        document.getElementById('error-message').innerHTML = error.errors[0].longMessage
+                        console.log('An error occurred:', error.errors)
+                      })
+                  })
+                  row.insertCell().appendChild(updateBtn)
+
+                  // Remove a member
+                  const removeBtn = document.createElement('button')
+                  removeBtn.textContent = 'Remove'
+                  removeBtn.addEventListener('click', async function (e) {
+                    e.preventDefault()
+                    await organization
+                      .removeMember(userId)
+                      .then((res) => {
+                        document.getElementById('response').innerHTML = JSON.stringify(res)
+                      })
+                      .catch((error) => {
+                        document.getElementById('error-container').removeAttribute('hidden')
+                        document.getElementById('error-message').innerHTML = error.errors[0].longMessage
+                        console.log('An error occurred:', error.errors)
+                      })
+                  })
+                  row.insertCell().appendChild(removeBtn)
+
+                  // Add a new member to the organization
+                  document.getElementById('add-member').addEventListener('click', () => {
+                    const userId = document.getElementById('member-user-id').value
+
+                    organization
+                      .addMember({ userId, role: 'org:member' })
+                      .then((res) => {
+                        document.getElementById('response').innerHTML = JSON.stringify(res)
+                      })
+                      .catch((error) => {
+                        document.getElementById('error-container').removeAttribute('hidden')
+                        document.getElementById('error-message').innerHTML = error.errors[0].longMessage
+                        console.log('An error occurred:', error.errors)
+                      })
+                  })
+                }
+              })
+            } catch (error) {
+              document.getElementById('error-container').removeAttribute('hidden')
+              document.getElementById('error-message').innerHTML = error.errors[0].longMessage
+              console.log('An error occurred:', error.errors)
+            }
           }
 
-          /* Style for table cells */
-          td,
-          th {
-            border: 1px solid black; /* Border for each cell */
-            padding: 2px; /* Optional: Add padding to cells */
-          }
-        
-      
-      
-        
+ /** + * Checks if a user is an admin of the + * currently active organization and + * renders the organization's memberships. + */ + async function checkAdminAndRenderMemberships() { + const organizationId = clerk.organization.id - + const { data } = await clerk.user.getOrganizationMemberships() -

Memberships List

- - - - - - - - - - - -
User IDIdentifierRole
- -
-

Add member

- - -
+ const organizationMemberships = data -

Response:

-

-
-        
-      
-    
-    ```
+            const currentMembership = organizationMemberships.find(
+              (membership) => membership.organization.id === organizationId,
+            )
+            const currentOrganization = currentMembership.organization
 
-    And your JavaScript file should look like this:
-
-    ```js {{ filename: 'main.js', mark: [13, 41, 58, 75] }}
-    import { Clerk } from '@clerk/clerk-js'
-
-    // Initialize Clerk with your Clerk publishable key
-    const clerk = new Clerk('{{pub_key}}')
-    await clerk.load()
-
-    if (clerk.user) {
-      // Check for an active organization
-      if (clerk.organization) {
-        // Render list of organization memberships
-        async function renderMemberships(organization, isAdmin) {
-          try {
-            const { data } = await organization.getMemberships()
-
-            const memberships = data
-            console.log(`getMemberships:`, memberships)
-
-            memberships.map((membership) => {
-              const membershipTable = document.getElementById('memberships_table')
-              const row = membershipTable.insertRow()
-              row.insertCell().textContent = membership.publicUserData.userId
-              row.insertCell().textContent = membership.publicUserData.identifier
-              row.insertCell().textContent = membership.role
-
-              // Add administrative actions:
-              // Add and remove a member, and update a member's role.
-              if (isAdmin) {
-                // Show add, update, remove member buttons
-                document.getElementById('add-member-container').removeAttribute('hidden')
-                document.getElementById('update-role-head').removeAttribute('hidden')
-                document.getElementById('remove-member-head').removeAttribute('hidden')
-
-                // Get the user ID of the member
-                const userId = membership.publicUserData.userId
-
-                // Update a member's role
-                const updateBtn = document.createElement('button')
-                updateBtn.textContent = 'Change role'
-                updateBtn.addEventListener('click', async function (e) {
-                  e.preventDefault()
-                  const role = membership.role === 'org:admin' ? 'org:member' : 'org:admin'
-                  await organization
-                    .updateMember({ userId, role })
-                    .then((res) => {
-                      document.getElementById('response').innerHTML = JSON.stringify(res)
-                    })
-                    .catch((error) => {
-                      document.getElementById('error-container').removeAttribute('hidden')
-                      document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-                      console.log('An error occurred:', error.errors)
-                    })
-                })
-                row.insertCell().appendChild(updateBtn)
-
-                // Remove a member
-                const removeBtn = document.createElement('button')
-                removeBtn.textContent = 'Remove'
-                removeBtn.addEventListener('click', async function (e) {
-                  e.preventDefault()
-                  await organization
-                    .removeMember(userId)
-                    .then((res) => {
-                      document.getElementById('response').innerHTML = JSON.stringify(res)
-                    })
-                    .catch((error) => {
-                      document.getElementById('error-container').removeAttribute('hidden')
-                      document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-                      console.log('An error occurred:', error.errors)
-                    })
-                })
-                row.insertCell().appendChild(removeBtn)
+            if (!currentOrganization) {
+              return
+            }
+            const isAdmin = currentMembership.role === 'org:admin'
 
-                // Add a new member to the organization
-                document.getElementById('add-member').addEventListener('click', () => {
-                  const userId = document.getElementById('member-user-id').value
+            console.log(`Organization:`, currentOrganization)
 
-                  organization
-                    .addMember({ userId, role: 'org:member' })
-                    .then((res) => {
-                      document.getElementById('response').innerHTML = JSON.stringify(res)
-                    })
-                    .catch((error) => {
-                      document.getElementById('error-container').removeAttribute('hidden')
-                      document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-                      console.log('An error occurred:', error.errors)
-                    })
-                })
-              }
-            })
-          } catch (error) {
-            document.getElementById('error-container').removeAttribute('hidden')
-            document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-            console.log('An error occurred:', error.errors)
+            renderMemberships(currentOrganization, isAdmin)
           }
-        }
 
-        /**
-         * Checks if a user is an admin of the
-         * currently active organization and
-         * renders the organization's memberships.
-         */
-        async function checkAdminAndRenderMemberships() {
-          const organizationId = clerk.organization.id
+          checkAdminAndRenderMemberships()
+        } else {
+          // If there is no active organization,
+          // mount Clerk's 
+          // to allow the user to set an organization as active
+          document.getElementById('app').innerHTML = `
+            

Select an organization to set it as active

+
+ ` - const { data } = await clerk.user.getOrganizationMemberships() + const orgSwitcherDiv = document.getElementById('org-switcher') - const organizationMemberships = data - - const currentMembership = organizationMemberships.find( - (membership) => membership.organization.id === organizationId, - ) - const currentOrganization = currentMembership.organization - - if (!currentOrganization) { - return - } - const isAdmin = currentMembership.role === 'org:admin' - - console.log(`Organization:`, currentOrganization) - - renderMemberships(currentOrganization, isAdmin) + clerk.mountOrganizationSwitcher(orgSwitcherDiv) } - - checkAdminAndRenderMemberships() } else { - // If there is no active organization, - // mount Clerk's - // to allow the user to set an organization as active document.getElementById('app').innerHTML = ` -

Select an organization to set it as active

-
+
` - const orgSwitcherDiv = document.getElementById('org-switcher') + const signInDiv = document.getElementById('sign-in') - clerk.mountOrganizationSwitcher(orgSwitcherDiv) + clerk.mountSignIn(signInDiv) } - } else { - document.getElementById('app').innerHTML = ` -
- ` - - const signInDiv = document.getElementById('sign-in') - - clerk.mountSignIn(signInDiv) - } - ``` + ``` +
diff --git a/docs/references/javascript/organization/membership-request.mdx b/docs/references/javascript/organization/membership-request.mdx index dbab9767fd..ec94efc8b2 100644 --- a/docs/references/javascript/organization/membership-request.mdx +++ b/docs/references/javascript/organization/membership-request.mdx @@ -54,174 +54,174 @@ function getMembershipRequests( The following example demonstrates how to use the `getMembershipRequests()` method to render a table of membership requests for the active organization. To ease the development process, the response or error message of a method will be displayed on the user interface. -']}> +']}> - For the following example, your HTML file should look like this: - - ```html {{ filename: 'index.html' }} - - - - - - - Clerk + JavaScript App - + + +
+ + + +

Membership Requests

+ + + + + + + + + + +
User IDIdentifierStatus
+ +

Response:

+

+
+          
+        
+      
+      ```
+
+      ```js {{ filename: 'main.js', mark: [13] }}
+      import { Clerk } from '@clerk/clerk-js'
+
+      // Initialize Clerk with your Clerk publishable key
+      const clerk = new Clerk('{{pub_key}}')
+      await clerk.load()
+
+      if (clerk.user) {
+        // Check for an active organization
+        if (clerk.organization) {
+          // Render list of organization membership requests
+          async function renderMembershipRequests(organization, isAdmin) {
+            try {
+              const { data } = await organization.getMembershipRequests()
+              const membershipRequests = data
+              console.log(`getMembershipRequests:`, membershipRequests)
+
+              membershipRequests.map((membershipRequest) => {
+                const requestsTable = document.getElementById('requests_table')
+                const row = requestsTable.insertRow()
+                row.insertCell().textContent = membershipRequest.publicUserData.userId
+                row.insertCell().textContent = membershipRequest.publicUserData.identifier
+                row.insertCell().textContent = membershipRequest.status
+
+                // Add administrative actions:
+                // Add member (removes request)
+                if (isAdmin) {
+                  // Show add member button
+                  document.getElementById('add-member-head').removeAttribute('hidden')
+
+                  // Get the user ID of the member
+                  const userId = membershipRequest.publicUserData.userId
+
+                  // Add member to organization
+                  const addBtn = document.createElement('button')
+                  addBtn.textContent = 'Add member'
+                  addBtn.addEventListener('click', async function (e) {
+                    e.preventDefault()
+
+                    const role = 'org:member'
+
+                    await organization
+                      .addMember({ userId, role })
+                      .then((res) => {
+                        document.getElementById('response').innerHTML = JSON.stringify(res)
+                      })
+                      .catch((error) => {
+                        document.getElementById('error-container').removeAttribute('hidden')
+                        document.getElementById('error-message').innerHTML = error.errors[0].longMessage
+                        console.log('An error occurred:', error.errors)
+                      })
+                  })
+                  row.insertCell().appendChild(addBtn)
+                }
+              })
+            } catch (error) {
+              document.getElementById('error-container').removeAttribute('hidden')
+              document.getElementById('error-message').innerHTML = error.errors[0].longMessage
+              console.log('An error occurred:', error.errors)
+            }
           }
-        
-      
-      
-        
- - -

Membership Requests

- - - - - - - - - - -
User IDIdentifierStatus
+ /** + * Checks if a user is an admin of the + * currently active organization and + * renders the organization's membership requests. + */ + async function checkAdminAndRenderRequests() { + const organizationId = clerk.organization.id -

Response:

-

+            const organizationMemberships = await clerk.user.getOrganizationMemberships()
 
-        
-      
-    
-    ```
-
-    And your JavaScript file should look like this:
-
-    ```js {{ filename: 'main.js', mark: [13] }}
-    import { Clerk } from '@clerk/clerk-js'
-
-    // Initialize Clerk with your Clerk publishable key
-    const clerk = new Clerk('{{pub_key}}')
-    await clerk.load()
-
-    if (clerk.user) {
-      // Check for an active organization
-      if (clerk.organization) {
-        // Render list of organization membership requests
-        async function renderMembershipRequests(organization, isAdmin) {
-          try {
-            const { data } = await organization.getMembershipRequests()
-            const membershipRequests = data
-            console.log(`getMembershipRequests:`, membershipRequests)
-
-            membershipRequests.map((membershipRequest) => {
-              const requestsTable = document.getElementById('requests_table')
-              const row = requestsTable.insertRow()
-              row.insertCell().textContent = membershipRequest.publicUserData.userId
-              row.insertCell().textContent = membershipRequest.publicUserData.identifier
-              row.insertCell().textContent = membershipRequest.status
-
-              // Add administrative actions:
-              // Add member (removes request)
-              if (isAdmin) {
-                // Show add member button
-                document.getElementById('add-member-head').removeAttribute('hidden')
-
-                // Get the user ID of the member
-                const userId = membershipRequest.publicUserData.userId
-
-                // Add member to organization
-                const addBtn = document.createElement('button')
-                addBtn.textContent = 'Add member'
-                addBtn.addEventListener('click', async function (e) {
-                  e.preventDefault()
-
-                  const role = 'org:member'
-
-                  await organization
-                    .addMember({ userId, role })
-                    .then((res) => {
-                      document.getElementById('response').innerHTML = JSON.stringify(res)
-                    })
-                    .catch((error) => {
-                      document.getElementById('error-container').removeAttribute('hidden')
-                      document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-                      console.log('An error occurred:', error.errors)
-                    })
-                })
-                row.insertCell().appendChild(addBtn)
-              }
-            })
-          } catch (error) {
-            document.getElementById('error-container').removeAttribute('hidden')
-            document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-            console.log('An error occurred:', error.errors)
-          }
-        }
+            const currentMembership = organizationMemberships.find(
+              (membership) => membership.organization.id === organizationId,
+            )
+            const currentOrganization = currentMembership.organization
 
-        /**
-         * Checks if a user is an admin of the
-         * currently active organization and
-         * renders the organization's membership requests.
-         */
-        async function checkAdminAndRenderRequests() {
-          const organizationId = clerk.organization.id
-
-          const organizationMemberships = await clerk.user.getOrganizationMemberships()
+            if (!currentOrganization) {
+              return
+            }
+            const isAdmin = currentMembership.role === 'org:admin'
 
-          const currentMembership = organizationMemberships.find(
-            (membership) => membership.organization.id === organizationId,
-          )
-          const currentOrganization = currentMembership.organization
+            console.log(`Organization:`, currentOrganization)
 
-          if (!currentOrganization) {
-            return
+            renderMembershipRequests(currentOrganization, isAdmin)
           }
-          const isAdmin = currentMembership.role === 'org:admin'
 
-          console.log(`Organization:`, currentOrganization)
+          checkAdminAndRenderRequests()
+        } else {
+          // If there is no active organization,
+          // mount Clerk's 
+          // to allow the user to set an organization as active
+          document.getElementById('app').innerHTML = `
+            

Select an organization to set it as active

+
+ ` - renderMembershipRequests(currentOrganization, isAdmin) - } + const orgSwitcherDiv = document.getElementById('org-switcher') - checkAdminAndRenderRequests() + clerk.mountOrganizationSwitcher(orgSwitcherDiv) + } } else { - // If there is no active organization, - // mount Clerk's - // to allow the user to set an organization as active document.getElementById('app').innerHTML = ` -

Select an organization to set it as active

-
+
` - const orgSwitcherDiv = document.getElementById('org-switcher') + const signInDiv = document.getElementById('sign-in') - clerk.mountOrganizationSwitcher(orgSwitcherDiv) + clerk.mountSignIn(signInDiv) } - } else { - document.getElementById('app').innerHTML = ` -
- ` - - const signInDiv = document.getElementById('sign-in') - - clerk.mountSignIn(signInDiv) - } - ``` + ``` +
diff --git a/docs/references/javascript/organization/organization.mdx b/docs/references/javascript/organization/organization.mdx index 6b669b4c9c..74d27b56d7 100644 --- a/docs/references/javascript/organization/organization.mdx +++ b/docs/references/javascript/organization/organization.mdx @@ -130,7 +130,7 @@ function update(params: UpdateOrganizationParams): Promise #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [10, 11] }} import { Clerk } from '@clerk/clerk-js' @@ -237,7 +237,7 @@ function destroy(): Promise #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [10, 11] }} import { Clerk } from '@clerk/clerk-js' @@ -351,74 +351,74 @@ function setLogo(params: SetOrganizationLogoParams): Promise #### Example -']}> +']}> - For the following example, your HTML file should look like this: - - ```html {{ filename: 'index.html' }} - - - - - - - Clerk + JavaScript App - - -
- - - - - - - - ``` - - And your JavaScript file should look like this: - - ```js {{ filename: 'main.js', mark: [14, 15] }} - import { Clerk } from '@clerk/clerk-js' - - // Initialize Clerk with your Clerk publishable key - const clerk = new Clerk('{{pub_key}}') - await clerk.load() + Use the following tabs to view the code necessary for each file. + + + ```html {{ filename: 'index.html' }} + + + + + + + Clerk + JavaScript App + + +
+ + + + + + + + ``` + + ```js {{ filename: 'main.js', mark: [14, 15] }} + import { Clerk } from '@clerk/clerk-js' + + // Initialize Clerk with your Clerk publishable key + const clerk = new Clerk('{{pub_key}}') + await clerk.load() + + if (clerk.user) { + // Check for an active organization + if (clerk.organization) { + // Update the organization's logo + document.getElementById('upload-logo').addEventListener('click', () => { + const orgLogo = document.getElementById('org-logo').files[0] + + clerk.organization + .setLogo({ file: orgLogo }) + .then((res) => console.log(res)) + .catch((error) => console.log('An error occurred:', error.errors)) + }) + } else { + // If there is no active organization, + // mount Clerk's + // to allow the user to set an organization as active + document.getElementById('app').innerHTML = ` +

Select an organization to set it as active

+
+ ` - if (clerk.user) { - // Check for an active organization - if (clerk.organization) { - // Update the organization's logo - document.getElementById('upload-logo').addEventListener('click', () => { - const orgLogo = document.getElementById('org-logo').files[0] + const orgSwitcherDiv = document.getElementById('org-switcher') - clerk.organization - .setLogo({ file: orgLogo }) - .then((res) => console.log(res)) - .catch((error) => console.log('An error occurred:', error.errors)) - }) + clerk.mountOrganizationSwitcher(orgSwitcherDiv) + } } else { - // If there is no active organization, - // mount Clerk's - // to allow the user to set an organization as active document.getElementById('app').innerHTML = ` -

Select an organization to set it as active

-
+
` - const orgSwitcherDiv = document.getElementById('org-switcher') + const signInDiv = document.getElementById('sign-in') - clerk.mountOrganizationSwitcher(orgSwitcherDiv) + clerk.mountSignIn(signInDiv) } - } else { - document.getElementById('app').innerHTML = ` -
- ` - - const signInDiv = document.getElementById('sign-in') - - clerk.mountSignIn(signInDiv) - } - ``` + ``` +
@@ -613,7 +613,7 @@ An _experimental_ interface that includes information about a user's permission. #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [10, 11] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/references/javascript/session.mdx b/docs/references/javascript/session.mdx index 3d7fe99a4d..a07db94a3b 100644 --- a/docs/references/javascript/session.mdx +++ b/docs/references/javascript/session.mdx @@ -179,7 +179,7 @@ function getToken(options?: GetTokenOptions): Promise #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [8, 9] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/references/javascript/user/create-metadata.mdx b/docs/references/javascript/user/create-metadata.mdx index bf8ab913b0..4ce35a88b5 100644 --- a/docs/references/javascript/user/create-metadata.mdx +++ b/docs/references/javascript/user/create-metadata.mdx @@ -31,7 +31,7 @@ function createEmailAddress(params: CreateEmailAddressParams): Promise']}> +']}> ```js {{ filename: 'main.js' }} import { Clerk } from '@clerk/clerk-js' @@ -119,7 +119,7 @@ function createPhoneNumber(params: CreatePhoneNumberParams): Promise']}> +']}> ```js {{ filename: 'main.js' }} import { Clerk } from '@clerk/clerk-js' @@ -207,7 +207,7 @@ function createWeb3Wallet(params: CreateWeb3WalletParams): Promise The following example adds `0x0123456789ABCDEF0123456789ABCDEF01234567` as a Web3 wallet for the user. If the user is not signed in, the user will be prompted to sign in. -']}> +']}> ```js {{ filename: 'main.js' }} import { Clerk } from '@clerk/clerk-js' @@ -316,69 +316,69 @@ Upon return, inspect within the `user.externalAccounts` the entry that correspon The following example demonstrates how to add a Notion account as an external account for the user. When the user selects the "Add Notion as a social connection" button, the user will be redirected to Notion to connect their account. After connecting their account, they will be redirected to the `/` route of your application, and the status of the connection will be displayed. -']}> +']}> - For the following example, your HTML file should look like this: - - ```html {{ filename: 'index.html' }} - - - - - - - Clerk + JavaScript App - - -
- -

- Notion verification status: - -

- - - - - - ``` - - And your JavaScript file should look like this: - - ```js {{ filename: 'main.js' }} - import { Clerk } from '@clerk/clerk-js' - - // Initialize Clerk with your Clerk publishable key - const clerk = new Clerk('{{pub_key}}') - await clerk.load() - - if (clerk.user) { - // Find the external account for the provider - const externalAccount = clerk.user.externalAccounts.find((p) => p.provider === 'notion') - // If the external account exists, display its status - document.getElementById('notion-status').innerHTML = externalAccount.verification.status - - // When the button is clicked, initiate the connection with the provider - document.getElementById('add-notion').addEventListener('click', async () => { - clerk.user - .createExternalAccount({ strategy: 'oauth_notion', redirect_url: '/' }) - .then((externalAccount) => { - window.location.href = externalAccount.verification.externalVerificationRedirectURL - }) - .catch((error) => { - console.log('An error occurred:', error.errors) - }) - }) - } else { - document.getElementById('app').innerHTML = ` -
- ` + Use the following tabs to view the code necessary for each file. + + + ```html {{ filename: 'index.html' }} + + + + + + + Clerk + JavaScript App + + +
+ +

+ Notion verification status: + +

+ + + + + + ``` + + ```js {{ filename: 'main.js' }} + import { Clerk } from '@clerk/clerk-js' + + // Initialize Clerk with your Clerk publishable key + const clerk = new Clerk('{{pub_key}}') + await clerk.load() + + if (clerk.user) { + // Find the external account for the provider + const externalAccount = clerk.user.externalAccounts.find((p) => p.provider === 'notion') + // If the external account exists, display its status + document.getElementById('notion-status').innerHTML = externalAccount.verification.status + + // When the button is clicked, initiate the connection with the provider + document.getElementById('add-notion').addEventListener('click', async () => { + clerk.user + .createExternalAccount({ strategy: 'oauth_notion', redirect_url: '/' }) + .then((externalAccount) => { + window.location.href = externalAccount.verification.externalVerificationRedirectURL + }) + .catch((error) => { + console.log('An error occurred:', error.errors) + }) + }) + } else { + document.getElementById('app').innerHTML = ` +
+ ` - const signInDiv = document.getElementById('sign-in') + const signInDiv = document.getElementById('sign-in') - clerk.mountSignIn(signInDiv) - } - ``` + clerk.mountSignIn(signInDiv) + } + ``` +
diff --git a/docs/references/javascript/user/password-management.mdx b/docs/references/javascript/user/password-management.mdx index 4fe9720720..adba4e6860 100644 --- a/docs/references/javascript/user/password-management.mdx +++ b/docs/references/javascript/user/password-management.mdx @@ -40,65 +40,65 @@ function updatePassword(params: UpdateUserPasswordParams): Promise ### Example -']}> +']}> - For the following example, your HTML file should look like this: - - ```html {{ filename: 'index.html' }} - - - - - - - Clerk + JavaScript App - - -
- -

Update password

- - -

- - - - - - ``` - - And your JavaScript file should look like this: - - ```js {{ filename: 'main.js' }} - import { Clerk } from '@clerk/clerk-js' - - // Initialize Clerk with your Clerk publishable key - const clerk = new Clerk('{{pub_key}}') - await clerk.load() - - if (clerk.user) { - document.getElementById('update-password-button').addEventListener('click', async function () { - const currentPassword = document.getElementById('current-password').value - - const newPassword = document.getElementById('new-password').value - clerk.user - .updatePassword({ currentPassword, newPassword }) - .then((response) => console.log(response)) - .catch((error) => { - document.getElementById('error').innerHTML = error.errors[0].longMessage - console.log('An error occurred:', error.errors) - }) - }) - } else { - document.getElementById('app').innerHTML = ` -
- ` - - const signInDiv = document.getElementById('sign-in') - - clerk.mountSignIn(signInDiv) - } - ``` + Use the following tabs to view the code necessary for each file. + + + ```html {{ filename: 'index.html' }} + + + + + + + Clerk + JavaScript App + + +
+ +

Update password

+ + +

+ + + + + + ``` + + ```js {{ filename: 'main.js' }} + import { Clerk } from '@clerk/clerk-js' + + // Initialize Clerk with your Clerk publishable key + const clerk = new Clerk('{{pub_key}}') + await clerk.load() + + if (clerk.user) { + document.getElementById('update-password-button').addEventListener('click', async function () { + const currentPassword = document.getElementById('current-password').value + + const newPassword = document.getElementById('new-password').value + clerk.user + .updatePassword({ currentPassword, newPassword }) + .then((response) => console.log(response)) + .catch((error) => { + document.getElementById('error').innerHTML = error.errors[0].longMessage + console.log('An error occurred:', error.errors) + }) + }) + } else { + document.getElementById('app').innerHTML = ` +
+ ` + + const signInDiv = document.getElementById('sign-in') + + clerk.mountSignIn(signInDiv) + } + ``` +
@@ -174,7 +174,7 @@ function removePassword(params: RemoveUserPasswordParams): Promise ### Example -']}> +']}> For the following example, your HTML file should look like this: diff --git a/docs/references/javascript/user/totp.mdx b/docs/references/javascript/user/totp.mdx index 30a3bb95f2..bbbeda7695 100644 --- a/docs/references/javascript/user/totp.mdx +++ b/docs/references/javascript/user/totp.mdx @@ -149,130 +149,130 @@ The following example assumes: - you have followed the [quickstart](/docs/quickstarts/javascript) in order to add Clerk to your JavaScript application - you have [enabled **Authenticator application** and **Backup codes** as multi-factor strategies in your Clerk Dashboard](/docs/authentication/configuration/sign-up-sign-in-options#authentication-strategies) -']}> +']}> - For the following example, your HTML file should look like this: - - ```html {{ filename: 'index.html' }} - - - - - - - Clerk + JavaScript App - - -
- - - - - - - - - -

Response:

-

-
-        
-      
-    
-    ```
-
-    And your JavaScript file should look like this:
-
-    ```js {{ filename: 'main.js' }}
-    import { Clerk } from '@clerk/clerk-js'
-
-    // Initialize Clerk with your Clerk publishable key
-    const clerk = new Clerk('{{pub_key}}')
-    await clerk.load()
-
-    if (clerk.user) {
-      // Create and verify TOTP
-      document.getElementById('create-totp').addEventListener('click', async () => {
-        clerk.user
-          .createTOTP()
-          .then((res) => {
-            // Show the TOTP container with the secret and verify button
-            document.getElementById('totp-container').removeAttribute('hidden')
-
-            // Display the secret to the user
-            document.getElementById('totp-secret').innerHTML = res.secret
-
-            // Add event listener to verify TOTP button
-            document.getElementById('verify-totp').addEventListener('click', async () => {
-              const code = document.getElementById('totp-code').value
-              clerk.user
-                .verifyTOTP({ code })
-                .then((res) => {
-                  document.getElementById('response').innerHTML = JSON.stringify(res)
-                })
-                .catch((error) => {
-                  document.getElementById('error-container').removeAttribute('hidden')
-                  document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-                  console.log('An error occurred:', error.errors)
-                })
+          
+          
+          
+
+          
+
+          

Response:

+

+
+          
+        
+      
+      ```
+
+      ```js {{ filename: 'main.js' }}
+      import { Clerk } from '@clerk/clerk-js'
+
+      // Initialize Clerk with your Clerk publishable key
+      const clerk = new Clerk('{{pub_key}}')
+      await clerk.load()
+
+      if (clerk.user) {
+        // Create and verify TOTP
+        document.getElementById('create-totp').addEventListener('click', async () => {
+          clerk.user
+            .createTOTP()
+            .then((res) => {
+              // Show the TOTP container with the secret and verify button
+              document.getElementById('totp-container').removeAttribute('hidden')
+
+              // Display the secret to the user
+              document.getElementById('totp-secret').innerHTML = res.secret
+
+              // Add event listener to verify TOTP button
+              document.getElementById('verify-totp').addEventListener('click', async () => {
+                const code = document.getElementById('totp-code').value
+                clerk.user
+                  .verifyTOTP({ code })
+                  .then((res) => {
+                    document.getElementById('response').innerHTML = JSON.stringify(res)
+                  })
+                  .catch((error) => {
+                    document.getElementById('error-container').removeAttribute('hidden')
+                    document.getElementById('error-message').innerHTML = error.errors[0].longMessage
+                    console.log('An error occurred:', error.errors)
+                  })
+              })
             })
-          })
-          .catch((error) => {
-            document.getElementById('error-container').removeAttribute('hidden')
-            document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-            console.log('An error occurred:', error.errors)
-          })
-      })
-
-      // Disable TOTP
-      document.getElementById('disable-totp').addEventListener('click', async () => {
-        clerk.user
-          .disableTOTP()
-          .then((res) => {
-            document.getElementById('response').innerHTML = JSON.stringify(res)
-          })
-          .catch((error) => {
-            document.getElementById('error-container').removeAttribute('hidden')
-            document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-            console.log('An error occurred:', error.errors)
-          })
-      })
-
-      // Create backup codes
-      document.getElementById('create-backup-codes').addEventListener('click', async () => {
-        clerk.user
-          .createBackupCode()
-          .then((res) => {
-            document.getElementById('response').innerHTML = JSON.stringify(res)
-          })
-          .catch((error) => {
-            document.getElementById('error-container').removeAttribute('hidden')
-            document.getElementById('error-message').innerHTML = error.errors[0].longMessage
-            console.log('An error occurred:', error.errors)
-          })
-      })
-    } else {
-      document.getElementById('app').innerHTML = `
-        
- ` - - const signInDiv = document.getElementById('sign-in') - - clerk.mountSignIn(signInDiv) - } - ``` + .catch((error) => { + document.getElementById('error-container').removeAttribute('hidden') + document.getElementById('error-message').innerHTML = error.errors[0].longMessage + console.log('An error occurred:', error.errors) + }) + }) + + // Disable TOTP + document.getElementById('disable-totp').addEventListener('click', async () => { + clerk.user + .disableTOTP() + .then((res) => { + document.getElementById('response').innerHTML = JSON.stringify(res) + }) + .catch((error) => { + document.getElementById('error-container').removeAttribute('hidden') + document.getElementById('error-message').innerHTML = error.errors[0].longMessage + console.log('An error occurred:', error.errors) + }) + }) + + // Create backup codes + document.getElementById('create-backup-codes').addEventListener('click', async () => { + clerk.user + .createBackupCode() + .then((res) => { + document.getElementById('response').innerHTML = JSON.stringify(res) + }) + .catch((error) => { + document.getElementById('error-container').removeAttribute('hidden') + document.getElementById('error-message').innerHTML = error.errors[0].longMessage + console.log('An error occurred:', error.errors) + }) + }) + } else { + document.getElementById('app').innerHTML = ` +
+ ` + + const signInDiv = document.getElementById('sign-in') + + clerk.mountSignIn(signInDiv) + } + ``` +
diff --git a/docs/references/javascript/user/user.mdx b/docs/references/javascript/user/user.mdx index 7e912c7ad7..d426a4c9cd 100644 --- a/docs/references/javascript/user/user.mdx +++ b/docs/references/javascript/user/user.mdx @@ -341,7 +341,7 @@ All props below are optional. In the following example, the user's first name is updated to "Test". -']}> +']}> ```js {{ filename: 'main.js', mark: [8, 9] }} import { Clerk } from '@clerk/clerk-js' @@ -411,7 +411,7 @@ function delete(): Promise #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [8, 9] }} import { Clerk } from '@clerk/clerk-js' @@ -513,60 +513,60 @@ function setProfileImage(params: SetProfileImageParams): Promise #### Example -']}> +']}> - For the following example, your HTML file should look like this: - - ```html {{ filename: 'index.html' }} - - - - - - - Clerk + JavaScript App - - -
- - - - - - - - ``` - - And your JavaScript file should look like this: - - ```js {{ filename: 'main.js' }} - import { Clerk } from '@clerk/clerk-js' - - // Initialize Clerk with your Clerk publishable key - const clerk = new Clerk('{{pub_key}}') - await clerk.load() - - if (clerk.user) { - // Update the user's profile image - document.getElementById('upload-image').addEventListener('click', () => { - const profileImage = document.getElementById('profile-image').files[0] - console.log(profileImage) - - clerk.user - .setProfileImage({ file: profileImage }) - .then((res) => console.log(res)) - .catch((error) => console.log('An error occurred:', error.errors)) - }) - } else { - document.getElementById('app').innerHTML = ` -
- ` + Use the following tabs to view the code necessary for each file. + + + ```html {{ filename: 'index.html' }} + + + + + + + Clerk + JavaScript App + + +
+ + + + + + + + ``` + + ```js {{ filename: 'main.js' }} + import { Clerk } from '@clerk/clerk-js' + + // Initialize Clerk with your Clerk publishable key + const clerk = new Clerk('{{pub_key}}') + await clerk.load() + + if (clerk.user) { + // Update the user's profile image + document.getElementById('upload-image').addEventListener('click', () => { + const profileImage = document.getElementById('profile-image').files[0] + console.log(profileImage) + + clerk.user + .setProfileImage({ file: profileImage }) + .then((res) => console.log(res)) + .catch((error) => console.log('An error occurred:', error.errors)) + }) + } else { + document.getElementById('app').innerHTML = ` +
+ ` - const signInDiv = document.getElementById('sign-in') + const signInDiv = document.getElementById('sign-in') - clerk.mountSignIn(signInDiv) - } - ``` + clerk.mountSignIn(signInDiv) + } + ``` +
@@ -632,7 +632,7 @@ function reload(p?: ClerkResourceReloadParams): Promise #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [7] }} import { Clerk } from '@clerk/clerk-js' @@ -680,7 +680,7 @@ function getSessions(): Promise #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [8, 9] }} import { Clerk } from '@clerk/clerk-js' @@ -817,7 +817,7 @@ function getOrganizationInvitations( #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [8, 9] }} import { Clerk } from '@clerk/clerk-js' @@ -918,7 +918,7 @@ function getOrganizationSuggestions( #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [8, 9] }} import { Clerk } from '@clerk/clerk-js' @@ -1012,7 +1012,7 @@ function getOrganizationMemberships( #### Example -']}> +']}> ```js {{ filename: 'main.js', mark: [8, 9] }} import { Clerk } from '@clerk/clerk-js' diff --git a/docs/users/metadata.mdx b/docs/users/metadata.mdx index e31c07d895..043c26e5b9 100644 --- a/docs/users/metadata.mdx +++ b/docs/users/metadata.mdx @@ -544,7 +544,7 @@ Updating this value overrides the previous value; it does not merge. To perform - "]}> + "]}> ```js {{ filename: 'main.js' }} import { Clerk } from '@clerk/clerk-js'