Socket
Socket
Sign inDemoInstall

use-facebook-auth

Package Overview
Dependencies
3
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-facebook-auth

A React based hook for facebook authentication.


Version published
Weekly downloads
3
increased by50%
Maintainers
1
Install size
233 kB
Created
Weekly downloads
 

Readme

Source

use-facebook-auth

A React based hook for facebook authentication.

npm version

Installiation

$ npm i use-facebook-auth

or

$ yarn add use-facebook-auth

Usage

This hook uses context and hooks to provide info throughout your application on wether or not you have an active session. You'll want to wrap your app by doing the following:

import FacebookProvider from 'use-facebook-auth';

const MY_APP_ID = 'xxxxxxxx';

ReactDOM.render(
	<React.StrictMode>
		<FacebookProvider options={{ appId: MY_APP_ID }}>
			<App />
		</FacebookProvider>
	</React.StrictMode>,
	document.getElementById('root')
);

Your App Id is the application you're using too authentcate against. Then on any page you wish to authenticate/logout/get sessino info you can use the following hook:

import { useFacebook } from 'use-facebook-auth';

const loginOptions = {
	scope: 'public_profile,email'
}

const MyMethod = () => {
	const {
		authenticatedSession: { // only comes back when authenticated
			accessToken: 'string';
			expiresIn: 'number';
			signedRequest: 'string';
			userID: 'string';
			grantedScopes: 'string'; // optional
			reauthorize_required_in: 'number'; // optional
		},
		authenticatedState: 'loading' | 'error' | 'authenticated' | 'unauthenticated',
		isAuthenticated: true | false, //derived from the auth state;
		loading: true | false, //derived from the auth state;
		logout(): void,
		login(loginOptions): void
	} = useFacebook();

	return (<div>Hello</div>);
}

Additional Provider Options

The Provider requires one option, the appId, but you can also pass in language and version if you wish to alter the defaults below:

ParameterDescription
appIdRequired The facebook app your authentication associates too.
versionDefault: v8.0 - provide a specific version
languageDefault: en_US - Provide the language you wish to see translations in

License

MIT Licensed

Up next

  • Add user session info to hook
  • Add example section to readme

Keywords

FAQs

Last updated on 11 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc