Subchapter 5.4
core-3/custom-sign-up.mdMarkdown8 KBView on GitHub
import { useSignUp } from '@clerk/nextjs' // or @clerk/react, @clerk/expo
const { signUp, errors, fetchStatus } = useSignUp()| Property | Type | Description |
|---|---|---|
signUp | SignUpFuture | Sign-up object with namespaced methods |
errors | Errors<SignUpFields> | Structured error object |
fetchStatus | 'idle' | 'fetching' | Network request status |
const { error } = await signUp.password({
emailAddress: 'user@example.com',
password: 'securePassword123',
firstName: 'Jane', // optional
lastName: 'Doe', // optional
})const { error } = await signUp.sso({
strategy: 'oauth_google', // or 'oauth_github', etc.
redirectUrl: '/dashboard', // where to go after SSO completes
redirectCallbackUrl: '/sso-callback', // intermediate callback route
})const { error } = await signUp.web3({ strategy: 'web3_solana_signature' })Use update() to add optional fields (name, metadata, legal acceptance, locale) to an existing sign-up before finalization.
const { error } = await signUp.update({
firstName: 'Jane',
lastName: 'Doe',
unsafeMetadata: { referralSource: 'twitter' },
legalAccepted: true,
})After creating a sign-up, verify the user’s email or phone:
// Send verification code
const { error } = await signUp.verifications.sendEmailCode()
// Verify the code
const { error } = await signUp.verifications.verifyEmailCode({ code: '123456' })// Send verification code
const { error } = await signUp.verifications.sendPhoneCode()
// Verify the code
const { error } = await signUp.verifications.verifyPhoneCode({ code: '123456' })// verificationUrl: where the user lands after clicking the email link (relative or absolute)
const { error } = await signUp.verifications.sendEmailLink({ verificationUrl: '/verify' })
// User clicks the link in their email to verifyAfter successful sign-up and verification, call finalize() to activate the session:
await signUp.finalize({
navigate: async ({ session, decorateUrl }) => {
const destination = session.currentTask
? `/sign-up/tasks/${session.currentTask.key}`
: '/'
const url = decorateUrl(destination)
// decorateUrl may return an absolute URL for Safari ITP
if (url.startsWith('http')) {
window.location.href = url
} else {
router.push(url)
}
},
})If signUp.isTransferable is true, the identifier matches an existing user and the sign-up should be transferred to a sign-in flow. This involves coordinating between sign-up and sign-in resources. See the transferable sign-up docs (opens in a new tab) for the full implementation.
Clear local sign-up state and start over:
signUp.reset()All methods return Promise<{ error: ClerkError | null }>. Errors are also available reactively on the hook:
const { signUp, errors } = useSignUp()
// Field-level errors
errors?.fields?.emailAddress // { code, message, longMessage? }
errors?.fields?.password // { code, message, longMessage? }
errors?.fields?.firstName // { code, message, longMessage? }
errors?.fields?.lastName // { code, message, longMessage? }
errors?.fields?.phoneNumber // { code, message, longMessage? }
errors?.fields?.username // { code, message, longMessage? }
errors?.fields?.code // { code, message, longMessage? }
// Global errors
errors?.global // ClerkGlobalHookError[] | null
// Raw error array
errors?.raw // ClerkError[] | nullFrom the docs (opens in a new tab). Uses phone OTP with inline comments for adapting to email OTP.
'use client'
import * as React from 'react'
import { useAuth, useSignUp } from '@clerk/nextjs'
import { useRouter } from 'next/navigation'
export default function SignUpPage() {
const { signUp, errors, fetchStatus } = useSignUp()
const { isSignedIn } = useAuth()