1.2.0 • Published 2 years ago
Share package react-facebook-login-hook
Description react-facebook-login-hook provides a React hook for Facebook login.
TypeScript support Lightweight - no external dependencies Quickstart: const { busy, logIn, logOut, getProfile } = useFacebookLogin({ appId: "YOUR_APP_ID" });
async function handleLogin() {
const response = await logIn();
if (response?.status === "connected") {
// response.authResponse.accessToken - process access token
const profile = await getProfile();
console.log("profile", profile);
}
}
return (
<button disabled={busy} onClick={handleLogin}>
{busy ? "Please wait..." : "Log in with Facebook"}
</button>
);API name type Description ready booleanIndicates if Facebook SDK script was loaded successfully busy booleanHas a value of true when the hook waits for the login process to complete logIn functionlogOut functionLog out Facebook user from your app getProfile functionGet data from a Facebook user's profile. Can be called after successful login
useFacebookLogin options/parameters name type Required Default value Description appId string✓ Your application ID scope stringpublic_profile,email Facebook permissions fields stringname,email,picture Facebook fields to fetch language stringen_US SDK language useRedirect booleanundefinedUse redirect flow onInitError functionundefinedCallback on init error (loading script element with Facebook SDK) sdkInitParams InitParamsundefinedParameters for the SDK initialization loginOptions LoginOptionsundefinedParameters for the Facebook login flow dialogParams DialogParamsundefinedParameters for the Facebook login dialog
name type Required Default value Description version stringv16.0 SDK version cookie booleanundefinedDetermines whether a cookie is created for the session or not localStorage booleantrue Determines whether a long-lived access token for the session can be saved in localStorage xfbml booleanundefinedDetermines whether XFBML tags used by social plugins are parsed frictionlessRequests booleanundefinedFrictionless Requests are available to games on Facebook.com or on mobile web using the JavaScript SDK.
name type Required Default value Description auth_type stringundefinedSupports 3 values: rerequest, reauthenticate, reauthorize return_scopes booleanundefinedWhen true, the granted scopes will be returned in a comma-separated list in the grantedScopes field of the authResponse enable_profile_selector booleanundefinedWhen true, prompt the user to grant permission for one or more Pages profile_selector_ids stringundefinedComma separated list of IDs to display in the profile selector
name type Required Default value Description redirect_uri stringundefinedThe URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog state stringundefinedA string value created by your app to maintain state between the request and callback. This parameter should be used for preventing Cross-site Request Forgery. response_type stringundefinedDetermines whether the response data included when the redirect back to the app occurs is in URL parameters or fragments
Other resources