Skip to content

Instantly share code, notes, and snippets.

@Tanver-Hasan
Last active September 28, 2021 10:02
Show Gist options
  • Save Tanver-Hasan/dc1effa7b8d67e964957f8db70aee031 to your computer and use it in GitHub Desktop.
Save Tanver-Hasan/dc1effa7b8d67e964957f8db70aee031 to your computer and use it in GitHub Desktop.
User AllowList
function userWhitelist(user, context, callback) {

    // Skipping rule execution if clientId and connection does not match
    if (context.clientID !== '[Client ID]' && context.connection !== '[Connection Name]'){
        return callback(null,user,context);
    }

    // Access should only be granted to verified users.
    if (!user.email || !user.email_verified) {
      return callback(new UnauthorizedError('Access denied.'));
    }
  
    //authorized users list
    const whitelist = [ '[email protected]', '[email protected]' ]; 

    const  userHasAccess = whitelist.some((email)=> email === user.email);
     
    // Deny Access if does not exist in the list
    if (!userHasAccess) {
      return callback(new UnauthorizedError('Access denied.'));
    }
  
    callback(null, user, context);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment