Is User Logged In
1
// Initialize provider
2
import Fortmatic from 'fortmatic';
3
import Web3 from 'web3';
4
​
5
const fm = new Fortmatic('YOUR_API_KEY');
6
window.web3 = new Web3(fm.getProvider());
7
​
8
let isUserLoggedIn = await fm.user.isLoggedIn();
9
console.log(isUserLoggedIn); // false
10
​
11
fm.user.login().then(() => {
12
isUserLoggedIn = await fm.user.isLoggedIn();
13
console.log(isUserLoggedIn); // true
14
});
Copied!
You may get a user's Fortmatic id and email by calling fm.user.getUser()
1
let isUserLoggedIn = await fm.user.isLoggedIn(); // false
2
let userData = await fm.user.getUser();
3
// {
4
// id: null
5
// email: null
6
// }
7
​
8
fm.user.login().then(() => {
9
userData = await fm.user.getUser();
10
// {
11
// id: 'FORTMATIC_USER_ID'
12
// email: '[email protected]'
13
// }
14
});
Copied!
Last modified 2yr ago
Copy link