Appearance
Login with UI
Once PrivyElements
is set up, you can start using the UI components to log users in. To do this, you need to use the useLogin
hook from @privy-io/expo
.
tsx
const {login} = useLogin();
The login
function returned takes a configuration object, detailed below, and returns a promise that resolves to the user's session.
ts
onPress={() => {
login({ loginMethods: ['email', 'sms']})
.then((session) => {
console.log('User logged in', session.user);
})
}}
Configuration
The login
function takes a configuration object with the following properties:
Parameter | Type | Description |
---|---|---|
loginMethods | LoginMethod[] | An array of login methods for your users to choose from. |
appearance.logo | string | (Optional) a url for the logo shown in the Login Method selection step. Aspect ratio should be 2:1. |
The supported loginMethods
are 'email'
, 'sms'
, 'discord'
, 'twitter'
, 'github'
, 'spotify'
, 'instagram'
, 'tiktok'
, 'linkedin'
, and 'apple'
.
INFO
If using one of the OAuth methods, make sure you have properly configured your app's allowed URL schemes in the Privy dashboard.
TIP
Apple login on iOS requires some additional setup for the best user experience possible. Please see this guide for more information.
This returns a promise that resolves to the LoginResult
.
Parameter | Type | Description |
---|---|---|
user | PrivyUser | The user that logged in, with all of their properties. |