Skip to content
Back

Need help setting up oauth with github

  • 0
  • React Native
  • Cloud
Axistro
16 Jun, 2025, 09:02

I saw the documentation but need help about the redirect url. In expo, the user account is created but I am redirected to a separate project in web , the smaller web window is opened and account is created but the smaller window does not close but opens the web app again (I assume redirects ) in that small window. Never used oauth before 🙂 Here is the code

TypeScript
const deepLink = new URL(makeRedirectUri({preferLocalhost: true}));
if (!deepLink.hostname) {
    deepLink.hostname = 'localhost';
}
const scheme = `${deepLink.protocol}//`; // e.g. 'exp://' or 'playground://'

// Start OAuth flow
const loginUrl = await account.createOAuth2Token(
    provider,
    `${deepLink}`,
    `${deepLink}`,
);

// Open loginUrl and listen for the scheme redirect
const result = await WebBrowser.openAuthSessionAsync(`${loginUrl}`, scheme);

// Extract credentials from OAuth redirect URL
const url = new URL(result.url);
const secret = url.searchParams.get('secret');
const userId = url.searchParams.get('userId');

// Create session with OAuth credentials
 const res = await account.createSession(userId, secret);
 console.log('Session created:', res);
// Redirect as needed
TL;DR
Developers struggling with setting up oauth with GitHub, specifically about redirect URLs in Expo. They are experiencing issues with the redirect not closing properly when web browser closes. Wondering if anything needs to be changed for deployment or APK version. Solution: Possible fix is to modify the redirect URL in the code.
Axistro
16 Jun, 2025, 09:03

I also wanted to know if I have to change anything if the site is deployed or I make a apk version instead of using localhost or expo

Axistro
16 Jun, 2025, 09:08

More info about expo redirecting to a wrong project when The web browser closes expo shows this

Axistro
16 Jun, 2025, 09:09

in web its like this

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more