
I'm encountering an OAuth2 error while implementing Google login with Appwrite. I need help to resolve this issue.
api:
`export async function signInWithGoogle() { try { const session = await account.createOAuth2Session( 'google', 'http://localhost:5173', 'http://localhost:5173/sign-in' ); return session; } catch (error) { console.log(error); return null; } }
export async function saveGoogleUser(user: { accountId: string; email: string; name: string; imageUrl: URL; }) { try { const newUser = await databases.createDocument( appwriteConfig.databaseId, appwriteConfig.userCollectionId, ID.unique(), { accountId: user.accountId, email: user.email, name: user.name, username: user.email.split('@')[0], imageUrl: user.imageUrl, } );
return newUser;
} catch (error) { console.log(error); return null; } }
export async function getGoogleUserInfo() { try { const currentAccount = await getAccount(); if (!currentAccount) throw Error;
const existingUser = await databases.listDocuments(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
[Query.equal("email", currentAccount.email)]
);
if (existingUser.documents.length > 0) {
return existingUser.documents[0];
}
const avatarUrl = avatars.getInitials(currentAccount.name);
return await saveGoogleUser({
accountId: currentAccount.$id,
name: currentAccount.name,
email: currentAccount.email,
imageUrl: avatarUrl,
});
} catch (error) { console.log(error); return null; } }
Recommended threads
- Error 400: redirect_uri_mismatch
The uri that I get from Appwrite and the one that I insert in the Google console are identical and yet I get this error while using Google Sign In:
- deployment on Vercel ??
- [SOLVED] Project with ID could not be fo...
async getCurrentUser() { try { return await this.account.get(); } catch (error) { console.log("Appwrite serive :: getCur...
