Appearance
Telegram ​
To authenticate your users with Telegram, use the useLoginWithTelegram
hook.
Use the login
function returned from the useLoginWithTelegram
hook to begin a Telegram authentication flow.
TIP
Before using theuseLoginWithTelegram
hook, ensure that Telegram is enabled in Socials tab of the Login Methods page on the the Privy dashboard, learn more.
Example usage ​
As an example, you might set up a LoginWithTelegram
component for your app that uses this methods, like below:
tsx
import {useLoginWithTelegram} from '@privy-io/react-auth';
export default function LoginWithTelegram() {
const {login, state} = useLoginWithTelegram();
const handleLogin = async () => {
try {
// Telegram's authentication pop-up will emerge, the user can then follow the steps to link its account.
// If the login is successful, the user will be authenticated and the authentication information will be returned as a result
const authenticationInfo = await login();
} catch (err) {
// Handle errors due to network availability, captcha failure, or input validation here
}
};
return <button onClick={handleLogin}>Log in with Telegram</button>;
}
Tracking login flow state ​
The state
variable returned from the useLoginWithTelegram
hook will always be one of the following values.
ts
type TelegramAuthFlowState =
| {status: 'initial'}
| {status: 'loading'}
| {status: 'done'}
| {status: 'error'; error: Error | null};
Learn more about conditional rendering with the state
variable in the state guide.