@@ -151,6 +151,44 @@ account.createOAuth2Session(
151
151
)
152
152
```
153
153
{% /tabsitem %}
154
+
155
+ {% tabsitem #react-native title="React Native" %}
156
+ ```client-react-native
157
+ import { Client, Account, OAuthProvider } from "appwrite";
158
+ import * as Linking from 'expo-linking';
159
+ import * as WebBrowser from 'expo-web-browser';
160
+
161
+ const client = new Client()
162
+ .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
163
+ .setProject('<PROJECT_ID>'); // Your project ID
164
+
165
+ const account = new Account(client);
166
+
167
+ // Create OAuth URL that works across Expo environments
168
+ const deepLink = new URL(Linking.createURL('oauth-callback', { isTripleSlashed: true }));
169
+ if (!deepLink.hostname) {
170
+ deepLink.hostname = 'localhost';
171
+ }
172
+
173
+ // Start OAuth flow
174
+ const loginUrl = await account.createOAuth2Token(
175
+ OAuthProvider.Github,
176
+ `${deepLink}/success`,
177
+ `${deepLink}/failure`,
178
+ ['repo', 'user'] // scopes (optional)
179
+ );
180
+
181
+ const result = await WebBrowser.openAuthSessionAsync(loginUrl);
182
+
183
+ // Extract credentials from OAuth redirect URL
184
+ const url = new URL(result.url);
185
+ const secret = url.searchParams.get('secret');
186
+ const userId = url.searchParams.get('userId');
187
+
188
+ // Create session with OAuth credentials
189
+ await account.createSession(userId, secret);
190
+ ```
191
+ {% /tabsitem %}
154
192
{% /tabs %}
155
193
156
194
You'll be redirected to the OAuth 2 provider's login page to log in. Once complete, your user will be redirected back to your app.
0 commit comments