Hi! I've trying to add the Apple sign in feature into my Expo App. I followed the docs, but I still receiving the error "Cannot set 'location.href'". Can someone help me, please? ππ»
The code is
β¨β¨```js
const makeRedirectUri = ({ preferLocalhost = false } = {}) => {
const redirectUri = Linking.createURL('auth', { scheme: appwrite-callback-${APPWRITE_PROJECT} });
if (preferLocalhost) {
const url = new URL(redirectUri);
url.hostname = 'localhost';
return url.toString();
}
return redirectUri;
};
const provider = OAuthProvider.Apple;
const loginWithApple = async () => {
setIsLoading(true);
try {
if (Platform.OS !== 'ios') {
return { error: { message: 'Apple Sign In solo estΓ‘ disponible en iOS' } };
}
// Create deep link that works across Expo environments
// Ensure localhost is used for the hostname to validation error for success/failure URLs
const deepLink = new URL(makeRedirectUri({ preferLocalhost: true }));
const scheme = `${deepLink.protocol}//`; // e.g. 'exp://' or 'appwrite-callback-<PROJECT_ID>://'
// Start OAuth flow
const loginUrl = await account.createOAuth2Token({
provider,
success: `${deepLink}`,
failure: `${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
await account.createSession({
userId,
secret
});
// Redirect as needed
} catch (error) {
console.error('OAuth error:', error);
setIsLoading(false);
throw error;
}
};
Recommended threads
- SMS OTP not delivered to Australian (+61...
Hey team! I'm having an issue with SMS OTP delivery to Australian phone numbers in my Appwrite Cloud project. What's happening: account.createPhoneToken() co...
- OAuth provider credentials reverting [CR...
Hi team, Iβm experiencing repeated OAuth configuration resets in my Appwrite project. ## Issue 1 β Google OAuth credentials reverting * I configure my own Goog...
- updateSession isn't working for google o...
I'm building an app using react native with expo. An image of my code is attached. The code is a useEffect that i have in a context that wraps the root layout ...