Headless Mode
Headless User Profile
Was this page helpful?
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
🚀 Stablecoin Accounts are live! Learn more
import { useIsLoggedIn } from "@dynamic-labs/sdk-react-core";
const isLoggedIn = useIsLoggedIn();
return <>{isLoggedIn ? <Profile /> : </Login>}</>
import { useDynamicContext } from "@dynamic-labs/sdk-react-core";
const { user } = useDynamicContext();
return (
<div className="user-details">
{user?.firstName && <p>First name: {user.firstName} </p>}
{user?.email && <p>E-Mail: {user.email} </p>}
{user?.alias && <p>Alias: {user.alias} </p>}
{user?.lastName && <p>Last name: {user.lastName} </p>}
{user?.jobTitle && <p>Job: {user.jobTitle} </p>}
{user?.phoneNumber && <p>Phone: {user.phoneNumber} </p>}
{user?.tShirtSize && <p>Tshirt size: {user.tShirtSize} </p>}
{user?.team && <p>Team: {user.team} </p>}
{user?.country && <p>Country: {user.country} </p>}
{user?.username && <p>Username: {user.username} </p>}
</div>
);
import { useUserUpdateRequest, useOtpVerificationRequest } from "@dynamic-labs/sdk-react-core";
const { verifyOtp } = useOtpVerificationRequest();
const { updateUser } = useUserUpdateRequest();
const [showUpdateForm, setShowUpdateForm] = useState(false);
const [showVerifyForm, setShowVerifyEmailForm] = useState(false);
const updateUserInfoFormSubmit = async (e) => {
e.preventDefault();
try {
setLoading(true);
// Call the updateUser function with the new values entered by the user
const { isEmailVerificationRequired } = await updateUser({
firstName: e.target[0].value,
email: e.target[1].value,
});
// If email verification is required, show the email verification form
if (isEmailVerificationRequired) {
setShowVerifyEmailForm(true);
}
} catch (e) {
console.log("Error", e);
} finally {
setLoading(false);
setShowUpdateForm(false);
}
};
// Handler for the email verification form submission
const onVerifyEmailFormSubmit = async (e) => {
e.preventDefault();
try {
setLoading(true);
const verificationToken = e.target[0].value;
// Call the verifyEmail function with the entered verification token
await verifyOtp(verificationToken);
} catch (e) {
console.log("Error", e);
} finally {
setLoading(false);
// Hide the email verification form after the process is completed
setShowVerifyEmailForm(false);
}
return false;
};
return (
<div>
{/* Render the profile update form */}
{showUpdateForm && (
<div>
<form onSubmit={onProfileFormSubmit} className="form">
<div className="form__row">
<label className="label" htmlFor="firstName">
First-Name
</label>
<input
id="firstName"
className="form__input"
defaultValue={user.firstName}
disabled={loading || showVerifyEmailForm}
/>
</div>
<div className="form__row">
<label className="label" htmlFor="email">
E-Mail
</label>
<input
type="email"
id="email"
className="form__input"
defaultValue={user.email}
disabled={loading || showVerifyEmailForm}
/>
</div>
<button
disabled={loading || showVerifyEmailForm}
className="form__button"
type="submit"
>
Save
</button>
</form>
</div>
)}
{/* Render the email verification form if needed */}
{showVerifyEmailForm && (
<form onSubmit={onVerifyEmailFormSubmit} className="form">
<h6>Verify Email</h6>
<div className="form__row">
<label htmlFor="verificationToken">Verification Token</label>
<input
disabled={loading}
pattern="^\d{6}$"
name="verificationToken"
/>
</div>
<button disabled={loading} className="form__button" type="submit">
Send
</button>
</form>
)}
<div>
)
import { useSocialAccounts } from "@dynamic-labs/sdk-react-core";
import { SocialIcon } from '@dynamic-labs/iconic';
const Avatar = ({ avatarUrl }) => {
return (
<div className="avatar">
<img src={avatarUrl} alt="avatar" />
</div>
);
};
const Icon = ({ provider }) => {
return (
<div className="icon-container">
<SocialIcon name={provider} />
</div>
);
};
const UserProfileSocialAccount = ({ provider }) => {
const {
linkSocialAccount,
unlinkSocialAccount,
isProcessing,
isLinked,
getLinkedAccountInformation,
} = useSocialAccounts();
const isProviderLinked = isLinked(provider);
const connectedAccountInfo = getLinkedAccountInformation(provider);
return (
<Flex>
<div className="icon">
{isProviderLinked ? (
<Avatar avatarUrl={connectedAccountInfo?.avatar} />
) : (
<Icon provider={provider} />
)}
</div>
<div className="label">
<p>{connectedAccountInfo?.publicIdentifier ?? provider}</p>
</div>
{isProviderLinked ? (
<button
onClick={() => unlinkSocialAccount(provider)}
loading={isProcessing}
>
Disconnect
</button>
) : (
<button
onClick={() => linkSocialAccount(provider)}
loading={isProcessing}
>
Connect
</button>
)}
</Flex>
);
};
const Socials = () => {
const providers = [
"discord",
"facebook",
"github",
"google",
"instagram",
"twitch",
"twitter",
];
return (
<Flex direction="column" align="stretch">
{providers.map((provider) => (
<UserProfileSocialAccount provider={provider} />
))}
</Flex>
);
};
Was this page helpful?