login-with-facebook

1.0.3 • Public • Published

Certainly! Here’s the revised README.md with the package name changed to login-with-facebook:

# Login with Facebook

A JavaScript package for integrating Facebook login functionality into your applications.

## Installation

You can install the package using npm. Run the following command in your terminal:

```bash
npm install login-with-facebook

Usage

To use the login-with-facebook package in your application, follow these steps:

1. Install the Package

First, make sure the package is installed:

npm install login-with-facebook

2. Include the Package in Your Code

Import the FacebookLogin class from the package:

const FacebookLogin = require('login-with-facebook');

3. Initialize the FacebookLogin Instance

Create a new instance of FacebookLogin with your Facebook App ID:

const fbLogin = new FacebookLogin('YOUR_APP_ID');

Replace 'YOUR_APP_ID' with your actual Facebook App ID, which you can obtain from the Facebook Developer Console.

4. Trigger the Facebook Login

Use the login method to start the login process:

fbLogin.login((error, userData) => {
  if (error) {
    console.error('Error:', error);
  } else {
    console.log('User Data:', userData);
  }
});

4.1 App.jsx

import React, { useState } from 'react';
import FacebookLogin from 'login-with-facebook';

const App = () => {
  const [userData, setUserData] = useState(null);
  const [error, setError] = useState(null);

  const fbLogin = new FacebookLogin('YOUR_APP_ID');

  const handleLogin = () => {
    fbLogin.login((err, data) => {
      if (err) {
        setError(err);
        setUserData(null);
      } else {
        setUserData(data);
        setError(null);
      }
    });
  };

  return (
    <div>
      <button onClick={handleLogin}>Login with Facebook</button>
    </div>
  );
};

export default App;
  • Callback Function: The login method accepts a callback function with two parameters:
    • error: An error message if the login fails (e.g., user cancelled login or did not fully authorize).
    • userData: An object containing user information if the login is successful. This object includes fields such as id, name, email, and picture.

5. Example Usage

Here's a complete example showing how to integrate the package into your application:

const FacebookLogin = require('login-with-facebook');

const fbLogin = new FacebookLogin('YOUR_APP_ID');

fbLogin.login((error, userData) => {
  if (error) {
    console.error('Error:', error);
  } else {
    console.log('User Data:', userData);
  }
});

6. Advanced Configuration (Optional)

If you need to configure additional options or change the Facebook SDK version, you can modify the index.js file in the package. For example, to use a different SDK version:

const fbLogin = new FacebookLogin('YOUR_APP_ID', 'v14.0'); // Example for SDK v14.0

7. Troubleshooting

  • Invalid App ID: Ensure that the Facebook App ID is correctly configured.
  • SDK Not Loaded: Verify that the Facebook SDK script is correctly loaded on your page.
  • Permission Errors: Check the permissions requested in the FB.login method and ensure they are correctly set in your Facebook App configuration.

If you encounter any issues or need further assistance, please refer to the Facebook Developer Documentation or open an issue on the GitHub repository.

License

This package is licensed under the ISC License.

Support

For any issues or questions, please open an issue on the GitHub repository.

Acknowledgements


### Notes

- **Repository URL**: Replace `https://github.com/your-repo/login-with-facebook/issues` with your actual GitHub repository URL.
- **License**: Ensure that the license section matches the license you choose for your package.

Feel free to modify any details or add more specific instructions as needed!

Package Sidebar

Install

npm i login-with-facebook

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

6.95 kB

Total Files

4

Last publish

Collaborators

  • technoa