@@ -3,3 +3,138 @@ title: Facebook Social Login with Web3Auth
33sidebar_label : Facebook
44description : " Facebook Social Login with Web3Auth | Documentation - Web3Auth"
55---
6+
7+ import FacebookToggle from " @site/static/images/dashboard/authentication-social-connections.png" ;
8+ import FacebookConnection from " @site/static/images/dashboard/facebook-connection.png" ;
9+
10+ Facebook Login enables users to sign in using their Facebook credentials. Web3Auth supports Facebook
11+ as a social login provider, allowing developers to offer a familiar and quick authentication method
12+ for users with Facebook accounts.
13+
14+ To integrate Facebook with Web3Auth, developers must first create a Facebook App via the
15+ [ Meta for Developers Console] ( https://developers.facebook.com/ ) .
16+
17+ :::success Enable on Dashboard
18+
19+ To use this feature, please enable ` Facebook ` from the Social Connections section in the
20+ [ Web3Auth Dashboard] ( https://dashboard.web3auth.io ) .
21+
22+ <div style = { { flexBasis: " 300px" , flexGrow: " 1" , textAlign: " center" }} >
23+ <img
24+ src = { FacebookToggle }
25+ style = { { alignSelf: " center" , maxWidth: " 100%" }}
26+ alt = " Toggle Facebook Connection on Dashboard"
27+ />
28+ </div >
29+
30+ > By default, Web3Auth uses its own pre-configured credentials for Facebook login.
31+
32+ :::
33+
34+ ## Create a Facebook app
35+
36+ 1 . Follow Facebook's instructions to
37+ [ create a new app] ( https://developers.facebook.com/docs/development/create-an-app ) .
38+ 2 . When creating an app, make sure to select ` Consumer ` from this screen to use Facebook Login.
39+ ![ Facebook OAuth2.0 App Dashboard] ( /guides/social-providers/facebook/facebook-app.png )
40+
41+ 3 . On the next screen, you'll be presented with different products you can integrate into your
42+ Facebook app. Click ** "Set Up"** in the card representing the ** Facebook Login** capability.
43+
44+ ![ Facebook OAuth2.0 App Dashboard] ( /guides/social-providers/facebook/facebook-login-setup.png )
45+
46+ 4 . Paste the following as a redirect URI into the "Valid OAuth Redirect URIs" field.
47+
48+ - https://auth.web3auth.io/auth
49+
50+ ![ Facebook OAuth2.0 App Dashboard] ( /guides/social-providers/facebook/facebook-login-settings-oauth.png )
51+
52+ 5 . Obtain the "App ID" and "App Secret" from the ** Settings > Basic** screen.
53+
54+ ![ Facebook OAuth2.0 App Dashboard] ( /guides/social-providers/facebook/facebook-app-id-secret.png )
55+
56+ ## Create a Facebook Connection
57+
58+ Follow these steps to create a Facebook connection:
59+
60+ 1 . Visit the [ Web3Auth Dashboard] ( https://dashboard.web3auth.io ) .
61+ 1 . Go to the ` Social Connections ` section.
62+ 1 . Click on the ` Settings ` icon near the Facebook connection.
63+ 1 . Enter the ` Auth Connection ID ` .
64+ 1 . Enter the ` Facebook App ID ` .
65+ 1 . Enter the ` Facebook App Secret ` .
66+ 1 . Finally, click on the ` Add Connection ` button.
67+
68+ <div style = { { flexBasis: " 300px" , flexGrow: " 1" , textAlign: " left" }} >
69+ <img
70+ src = { FacebookConnection }
71+ style = { { alignSelf: " center" , maxWidth: " 100%" }}
72+ alt = " Facebook Connection"
73+ />
74+ </div >
75+
76+ ## Usage
77+
78+ ### Initialize Web3Auth
79+
80+ Wrap your app with the ` Web3AuthProvider ` . This provider should be as close to the root of your
81+ React tree as possible.
82+
83+ ``` js title="Example: React + Vite (main.tsx)"
84+ import { StrictMode } from " react" ;
85+ import { createRoot } from " react-dom/client" ;
86+ import " ./index.css" ;
87+
88+ import { Web3AuthProvider , WEB3AUTH_NETWORK } from " @web3auth/modal/react" ;
89+
90+ import App from " ./App.tsx" ;
91+
92+ createRoot (document .getElementById (" root" )! ).render (
93+ < StrictMode>
94+ < Web3AuthProvider
95+ config= {{
96+ web3AuthOptions: {
97+ clientId: " WEB3AUTH_CLIENT_ID" , // Replace with your Client ID
98+ web3AuthNetwork: WEB3AUTH_NETWORK .SAPPHIRE_DEVNET ,
99+ },
100+ }}
101+ >
102+ < App / >
103+ < / Web3AuthProvider>
104+ < / StrictMode>
105+ );
106+ ```
107+
108+ Since, the ` Facebook Connection ` details are available from Dashboard, developers don't need to pass
109+ any additional parameters to the ` Web3AuthProvider ` .
110+
111+ > Follow our [ Quickstart Guide] ( /quick-start ) to setup the basic flow.
112+
113+ ### Login with Google
114+
115+ ``` jsx
116+ import { useWeb3AuthConnect , WALLET_CONNECTORS , AUTH_CONNECTION } from " @web3auth/modal/react" ;
117+ import { useAccount } from " wagmi" ;
118+
119+ function LoginPage () {
120+ const { connectTo } = useWeb3AuthConnect ();
121+ const { address } = useAccount ();
122+
123+ const loginWithFacebook = async () => {
124+ await connectTo (WALLET_CONNECTORS .AUTH , {
125+ // highlight-start
126+ authConnectionId: " facebook-auth-connection-id" ,
127+ authConnection: AUTH_CONNECTION .FACEBOOK ,
128+ // highlight-end
129+ });
130+ };
131+
132+ return (
133+ < div>
134+ < button onClick= {() => loginWithFacebook ()}> Login with Facebook< / button>
135+ < p> Address: {address}< / p>
136+ {/* 0xA8b29d40d0FE6a0c153A5759B1f0059d8b7654c5 */ }
137+ < / div>
138+ );
139+ }
140+ ```
0 commit comments