-
+
-
-
-
- ```
+
+
+
+ ```
- ```js {{ filename: 'main.js', collapsible: true }}
- import { Clerk } from '@clerk/clerk-js'
+ ```js {{ filename: 'main.js', collapsible: true }}
+ import { Clerk } from '@clerk/clerk-js'
- // Initialize Clerk with your Clerk publishable key
- const clerk = new Clerk('{{pub_key}}')
- await clerk.load()
+ const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
- if (clerk.user) {
- // Mount user button component
- document.getElementById('signed-in').innerHTML = `
-
- `
+ const clerk = new Clerk(pubKey)
+ await clerk.load()
- const userbuttonDiv = document.getElementById('user-button')
+ if (clerk.user) {
+ // Mount user button component
+ document.getElementById('signed-in').innerHTML = `
+
+ `
- clerk.mountUserButton(userbuttonDiv)
- } else {
- // Handle the sign-in form
- document.getElementById('sign-in-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-in process
- await clerk.client.signIn.create({
- identifier: emailAddress,
- password,
- })
-
- // Hide sign-in form
- document.getElementById('sign-in').setAttribute('hidden', '')
- // Show verification form
- document.getElementById('verifying').removeAttribute('hidden')
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
- })
+ const userbuttonDiv = document.getElementById('user-button')
+
+ clerk.mountUserButton(userbuttonDiv)
+ } else {
+ // Handle the sign-in form
+ document.getElementById('sign-in-form').addEventListener('submit', async (e) => {
+ e.preventDefault()
+
+ const formData = new FormData(e.target)
+ const emailAddress = formData.get('email')
+ const password = formData.get('password')
- // Handle the verification form
- document.getElementById('verifying').addEventListener('submit', async (e) => {
- const formData = new FormData(e.target)
- const totp = formData.get('totp')
- const backupCode = formData.get('backupCode')
-
- try {
- const useBackupCode = backupCode ? true : false
- const code = backupCode ? backupCode : totp
-
- // Attempt the TOTP or backup code verification
- const signInAttempt = await clerk.client.signIn.attemptSecondFactor({
- strategy: useBackupCode ? 'backup_code' : 'totp',
- code: code,
- })
-
- // If verification was completed, set the session to active
- // and redirect the user
- if (signInAttempt.status === 'complete') {
- await clerk.setActive({ session: signInAttempt.createdSessionId })
-
- location.reload()
- } else {
- // If the status is not complete, check why. User may need to
- // complete further steps.
- console.error(signInAttempt)
- }
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
+ try {
+ // Start the sign-in process
+ await clerk.client.signIn.create({
+ identifier: emailAddress,
+ password,
})
- }
- ```
-
-
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign in
-
-
-
+ // Hide sign-in form
+ document.getElementById('sign-in').setAttribute('hidden', '')
+ // Show verification form
+ document.getElementById('verifying').removeAttribute('hidden')
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
+ }
+ })
+
+ // Handle the verification form
+ document.getElementById('verifying').addEventListener('submit', async (e) => {
+ const formData = new FormData(e.target)
+ const totp = formData.get('totp')
+ const backupCode = formData.get('backupCode')
+
+ try {
+ const useBackupCode = backupCode ? true : false
+ const code = backupCode ? backupCode : totp
+
+ // Attempt the TOTP or backup code verification
+ const signInAttempt = await clerk.client.signIn.attemptSecondFactor({
+ strategy: useBackupCode ? 'backup_code' : 'totp',
+ code: code,
+ })
-
-
-
-
-
- ```
-
-
+ // If verification was completed, set the session to active
+ // and redirect the user
+ if (signInAttempt.status === 'complete') {
+ await clerk.setActive({ session: signInAttempt.createdSessionId })
+
+ location.reload()
+ } else {
+ // If the status is not complete, check why. User may need to
+ // complete further steps.
+ console.error(signInAttempt)
+ }
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
+ }
+ })
+ }
+ ```
+
diff --git a/docs/custom-flows/email-password.mdx b/docs/custom-flows/email-password.mdx
index 68d9ca6bec..2b751f5fac 100644
--- a/docs/custom-flows/email-password.mdx
+++ b/docs/custom-flows/email-password.mdx
@@ -157,211 +157,104 @@ This guide will walk you through how to build a custom email/password sign-up an
- "]}>
-
- Use the following tabs to view the code necessary for each file.
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign up
-
-
-
-
-
-
-
-
- ```
-
- ```js {{ filename: 'main.js', collapsible: true }}
- 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 email and password provided
- 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 (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
- })
+
+ ```html {{ filename: 'index.html', collapsible: true }}
+
+
+
+
+
+ Clerk + JavaScript App
+
+
+
+
+
+
Sign up
+
+
- // Handle the verification form
- document.getElementById('verifying').addEventListener('submit', async (e) => {
- const formData = new FormData(e.target)
- const code = formData.get('code')
-
- try {
- // Use the code the user provided to attempt verification
- const signUpAttempt = await clerk.client.signUp.attemptEmailAddressVerification({
- code,
- })
-
- // Now that the user is created, set the session to active.
- await clerk.setActive({ session: signUpAttempt.createdSessionId })
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
- })
+
+
+
+
+
+ ```
+
+ ```js {{ filename: 'main.js', collapsible: true }}
+ import { Clerk } from '@clerk/clerk-js'
+
+ const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
+
+ const clerk = new Clerk(pubKey)
+ 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 email and password provided
+ 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 (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
}
- ```
-
-
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign up
-
-
+ })
-
+ // Handle the verification form
+ document.getElementById('verifying').addEventListener('submit', async (e) => {
+ const formData = new FormData(e.target)
+ const code = formData.get('code')
+
+ try {
+ // Use the code the user provided to attempt verification
+ const signUpAttempt = await clerk.client.signUp.attemptEmailAddressVerification({
+ code,
+ })
-
-
-
-
-
- ```
-
-
+ // Now that the user is created, set the session to active.
+ await clerk.setActive({ session: signUpAttempt.createdSessionId })
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
+ }
+ })
+ }
+ ```
+
@@ -679,175 +572,86 @@ This guide will walk you through how to build a custom email/password sign-up an
- "]}>
-
- Use the following tabs to view the code necessary for each file.
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign in
-
-
-
-
-
-
- ```
-
- ```js {{ filename: 'main.js', collapsible: true }}
- 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-in form
- document.getElementById('sign-in-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-in process
- const signInAttempt = await clerk.client.signIn.create({
- identifier: emailAddress,
- password,
- })
-
- // If the sign-in is complete, set the user as active
- if (signInAttempt.status === 'complete') {
- await clerk.setActive({ session: signInAttempt.createdSessionId })
-
- location.reload()
- } else {
- // If the status is not complete, check why. User may need to
- // complete further steps.
- console.error(JSON.stringify(signInAttempt, null, 2))
- }
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
+
+ ```html {{ filename: 'index.html', collapsible: true }}
+
+
+
+
+
+ Clerk + JavaScript App
+
+
+
+
+
-
-
-
-
-
- ```
-
-
+ // If the sign-in is complete, set the user as active
+ if (signInAttempt.status === 'complete') {
+ await clerk.setActive({ session: signInAttempt.createdSessionId })
+
+ location.reload()
+ } else {
+ // If the status is not complete, check why. User may need to
+ // complete further steps.
+ console.error(JSON.stringify(signInAttempt, null, 2))
+ }
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
+ }
+ })
+ }
+ ```
+
diff --git a/docs/custom-flows/email-sms-otp.mdx b/docs/custom-flows/email-sms-otp.mdx
index 4f62634c30..af644e1dcf 100644
--- a/docs/custom-flows/email-sms-otp.mdx
+++ b/docs/custom-flows/email-sms-otp.mdx
@@ -135,205 +135,101 @@ 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.
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign up
-
-
-
-
-
-
-
-
- ```
-
- ```js {{ filename: 'main.js', collapsible: true }}
- 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 phoneNumber = formData.get('phone')
-
- try {
- // Start the sign-up process using the phone number method
- await clerk.client.signUp.create({ phoneNumber })
- await clerk.client.signUp.preparePhoneNumberVerification()
- // Hide sign-up form
- document.getElementById('sign-up').setAttribute('hidden', '')
- // Show verification form
- document.getElementById('verifying').removeAttribute('hidden')
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
- })
+
+ ```html {{ filename: 'index.html', collapsible: true }}
+
+
+
+
+
+ Clerk + JavaScript App
+
+
+
+
+
+
Sign up
+
+
- // 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.attemptPhoneNumberVerification({
- code,
- })
-
- // Now that the user is created, set the session to active.
- await clerk.setActive({ session: verify.createdSessionId })
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
- })
+
+
+
+
+
+ ```
+
+ ```js {{ filename: 'main.js', collapsible: true }}
+ import { Clerk } from '@clerk/clerk-js'
+
+ const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
+
+ const clerk = new Clerk(pubKey)
+ 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 phoneNumber = formData.get('phone')
+
+ try {
+ // Start the sign-up process using the phone number method
+ await clerk.client.signUp.create({ phoneNumber })
+ await clerk.client.signUp.preparePhoneNumberVerification()
+ // Hide sign-up form
+ document.getElementById('sign-up').setAttribute('hidden', '')
+ // Show verification form
+ document.getElementById('verifying').removeAttribute('hidden')
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
}
- ```
-
-
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign up
-
-
-
-
+ })
+
+ // 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.attemptPhoneNumberVerification({
+ code,
+ })
-
-
-
-
-
- ```
-
-
+ // Now that the user is created, set the session to active.
+ await clerk.setActive({ session: verify.createdSessionId })
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
+ }
+ })
+ }
+ ```
+
@@ -541,241 +437,119 @@ 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.
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign in
-
-
-
-
-
-
-
-
- ```
-
- ```js {{ filename: 'main.js', collapsible: true }}
- 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-in form
- document.getElementById('sign-in-form').addEventListener('submit', async (e) => {
- e.preventDefault()
-
- const formData = new FormData(e.target)
- const phone = formData.get('phone')
-
- try {
- // Start the sign-in process using the user's identifier.
- // In this case, it's their phone number.
- const { supportedFirstFactors } = await clerk.client.signIn.create({
- identifier: phone,
- })
-
- // Find the phoneNumberId from all the available first factors for the current sign-in
- const firstPhoneFactor = supportedFirstFactors.find((factor) => {
- return factor.strategy === 'phone_code'
- })
-
- const { phoneNumberId } = firstPhoneFactor
-
- // Prepare first factor verification, specifying
- // the phone code strategy.
- await clerk.client.signIn.prepareFirstFactor({
- strategy: 'phone_code',
- phoneNumberId,
- })
-
- // Hide sign-in form
- document.getElementById('sign-in').setAttribute('hidden', '')
- // Show verification form
- document.getElementById('verifying').removeAttribute('hidden')
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
+
+ ```html {{ filename: 'index.html', collapsible: true }}
+
+
+
+
+
+ Clerk + JavaScript App
+
+
+
+
+
+
Sign in
+
+
+
+
+
+
+
+
+ ```
+
+ ```js {{ filename: 'main.js', collapsible: true }}
+ import { Clerk } from '@clerk/clerk-js'
+
+ const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
+
+ const clerk = new Clerk(pubKey)
+ 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-in form
+ document.getElementById('sign-in-form').addEventListener('submit', async (e) => {
+ e.preventDefault()
+
+ const formData = new FormData(e.target)
+ const phone = formData.get('phone')
+
+ try {
+ // Start the sign-in process using the user's identifier.
+ // In this case, it's their phone number.
+ const { supportedFirstFactors } = await clerk.client.signIn.create({
+ identifier: phone,
})
- // 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.signIn.attemptFirstFactor({
- strategy: 'phone_code',
- code,
- })
-
- // Now that the user is created, set the session to active.
- await clerk.setActive({ session: verify.createdSessionId })
- } catch (error) {
- // See https://clerk.com/docs/custom-flows/error-handling
- // for more info on error handling
- console.error(error)
- }
+ // Find the phoneNumberId from all the available first factors for the current sign-in
+ const firstPhoneFactor = supportedFirstFactors.find((factor) => {
+ return factor.strategy === 'phone_code'
})
+
+ const { phoneNumberId } = firstPhoneFactor
+
+ // Prepare first factor verification, specifying
+ // the phone code strategy.
+ await clerk.client.signIn.prepareFirstFactor({
+ strategy: 'phone_code',
+ phoneNumberId,
+ })
+
+ // Hide sign-in form
+ document.getElementById('sign-in').setAttribute('hidden', '')
+ // Show verification form
+ document.getElementById('verifying').removeAttribute('hidden')
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
}
- ```
-
-
-
-
- ```html {{ filename: 'index.html', collapsible: true }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-
-
Sign in
-
-
-
-
+ })
-
-
-
-
-
- ```
-
-
+ // 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.signIn.attemptFirstFactor({
+ strategy: 'phone_code',
+ code,
+ })
+
+ // Now that the user is created, set the session to active.
+ await clerk.setActive({ session: verify.createdSessionId })
+ } catch (error) {
+ // See https://clerk.com/docs/custom-flows/error-handling
+ // for more info on error handling
+ console.error(error)
+ }
+ })
+ }
+ ```
+
diff --git a/docs/custom-flows/error-handling.mdx b/docs/custom-flows/error-handling.mdx
index 81b08db8e2..d402febe8b 100644
--- a/docs/custom-flows/error-handling.mdx
+++ b/docs/custom-flows/error-handling.mdx
@@ -112,223 +112,110 @@ The following example uses the [email & password sign-in custom flow](/docs/cust
- "]}>
-
- Use the following tabs to view the code necessary for each file.
-
-
- ```html {{ filename: 'index.html' }}
-
-
-
-
-
- Clerk + JavaScript App
-
-
-
-
-