Is User Logged In

// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

let isUserLoggedIn = await fm.user.isLoggedIn();
console.log(isUserLoggedIn); // false

fm.user.login().then(() => {
  isUserLoggedIn = await fm.user.isLoggedIn();
  console.log(isUserLoggedIn); // true
});

You may get a user's Fortmatic id and email by calling fm.user.getUser()

let isUserLoggedIn = await fm.user.isLoggedIn(); // false
let userData = await fm.user.getUser(); 
// {
//   id: null
//   email: null
// }

fm.user.login().then(() => {
  userData = await fm.user.getUser(); 
  // {
  //   id: 'FORTMATIC_USER_ID'
  //   email: 'example@fortmatic.com'
  // }
});

Last updated