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
- Courtesy limit reset for non-profit migr...
Hi Team! I'm the architect for a 501(c)(3) non-profit project (Aaria's Blue Elephant) and we just hit our Free plan Database Read limit (currently at 164%). Th...
- {"code": 1008, "message": "Invalid Origi...
Nothing has changed in my application or console settings so I'm curious as to what I need to do to fix this. I already have the client registered so I'm not en...
- RBAC design question
Hi, I am trying to create RBAC so we will have multiple orgs in the app each org will have 3 roles (admin, member and read only) what is the best way to go ab...