Phone Login
Implementing custom phone number authentication with Para
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Implementing custom phone number authentication with Para
const checkUserExists = async (phoneNumber: string) => {
const isExistingUser = await para.checkIfUserExists({ phoneNumber });
if (isExistingUser) {
// Proceed with login flow for existing user
} else {
// Proceed with signup flow for new user
}
};
const loginExistingUser = async (phoneNumber: string) => {
// Request SMS verification code to be sent
await para.initiateUserLogin({ phoneNumber });
// Proceed to verification step
};
const registerNewUser = async (phoneNumber: string) => {
// Create new user with provided phone number
await para.createUser({ phoneNumber });
// SMS verification code will be sent
// Proceed to verification step
};
const verifyAndCreateWallet = async (phoneNumber: string, verificationCode: string) => {
try {
// For new users:
const setupUrl = await para.verifyPhoneNumber({
phoneNumber,
verificationCode
});
if (setupUrl) {
// Open popup for passkey creation
const popupWindow = window.open(setupUrl, "signUpPopup", "popup=true");
// Wait for passkey setup and wallet creation
await para.waitForPasskeyAndCreateWallet();
}
// For existing users:
// const { needsWallet } = await para.verifyPhoneAndLogin({
// phoneNumber,
// verificationCode
// });
//
// if (needsWallet) {
// await para.createWallet({ type: WalletType.EVM, skipDistribute: false });
// }
// Get user wallet information
const wallets = Object.values(await para.getWallets());
} catch (error) {
// Handle verification errors
}
};