Check granted permissions

Check granted permissions

You can use the SDK to get the list of permissions granted by the user. In other words, the permissions available under a given authToken.

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect({ 
   appId: '<app-id>', 
   appSecret: '<secret>',
}); 
const cloudAccount = handCashConnect.getAccountFromAuthToken(authToken);

const userPermissions = await cloudAccount.profile.getPermissions();
console.log(userPermissions)


This is extremely useful if you have different apps in the same environment or you recently changed your app permissions.

For example, you can redirect the user to HandCash to grant permissions again if the authToken only has access to the old set of permissions

const {HandCashConnect, Permissions} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect({ 
   appId: '<app-id>', 
   appSecret: '<secret>',
}); 
const cloudAccount = handCashConnect.getAccountFromAuthToken(authToken);

const userPermissions = await cloudAccount.profile.getPermissions();
if (!userPermissions.includes(Permissions.Pay)) {
  const redirectUrl = handCashConnect.getRedirectionUrl();
  // redirect the user to HandCash to grant the new permissions set
}