If user's action is recorded somewhere, for example, buy a product, post a comment,... then user's ID or user's username must be available.
In this case you need to create a Joomla account for your user.
Step 1. User logins with Facebook successfully
Step 2.a. If he has already had an account (by checking email, etc...), you get the account's username login (no need for password).
Step 2.b. If he doesn't have an account, you create a dummy account for him. A better way is asking him for providing a username (and password), let him know that he only does this once, this username can be used to log into the site if for some reasons he can't use Facebook login. Use his username to log him in.
Here is the sample code I use for this task in my community component.
/*
* Get user info by email address.
* If user is already registered, we log user in. If we haven't saved
* this connection yet, we save it from now.
* If user is not registered yet, we redirect user to register function.
*/
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName(array('id', 'username')))
->from($db->quoteName('#__users'))
->where($db->quoteName('email') . ' = ' . $db->quote($email));
$user = $db->setQuery($query)->loadObject();
if (isset($user->id))
{
// Log user in.
$options = array('action' => 'core.login.site');
$response = array('username' => $user->username);
JPluginHelper::importPlugin('user');
$result = $app->triggerEvent('onUserLogin', array($response, $options));
$app->redirect(JRoute::_('index.php?Itemid=' . $itemId, false));
return true;
}
else
{
$app->redirect(JRoute::_('index.php?option=com_cmcommunity&task=registration.socialRegister&network=' . $this->pluginId, false));
return false;
}