Currently, only Google Auth login is active in my project.
When the user clicks the button, Chrome WebView opens. After logging into Google and closing the browser, the membership appears via Appwrite, but the session does not start. It gives a token error. The error I get is only as follows: "AppwriteException: Invalid token passed in the request."
Here's how the code looks:
`` static async signInWithGoogle(): Promise<User> {
try {
const redirectUri = Linking.createURL('oauth-callback');
const loginUrl = await account.createOAuth2Token({
provider: OAuthProvider.Google,
failure: redirectUri,
success: redirectUri
});
if (!loginUrl) {
console.error('No OAuth URL returned from Appwrite');
throw new Error('OAuth URL not generated');
}
const result = await WebBrowser.openAuthSessionAsync(
loginUrl.toString(),
redirectUri
);
if (result.type === 'success' && result.url) {
const url = new URL(result.url);
const userId = url.searchParams.get('userId');
const secret = url.searchParams.get('secret');
await account.createSession({
secret: secret!,
userId: userId!
});
const currentUser = await this.getCurrentUser();
this.saveUserToDatabase(currentUser).catch(error => {
console.error('Error saving user to database:', error);
});
return currentUser;
} else if (result.type === 'cancel') {
throw new Error('OAuth sign in was cancelled');
} else {
throw new Error('OAuth sign in failed');
}
} catch (error) {
console.error('Sign in with Google error:', error);
throw error;
}
}``