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
- Paused project can't activate
I have failed to reactivate one my projects which had been paused
- Site deployment keeps getting failed
Hi good folks, need a hand with Sites deploy Error on every deploy: Synchronous function execution timed out... duration doesn't exceed 30 seconds [exact log ...
- Unknown attribute type: varchar / text
Since the `string` type is deprecated I tried using `varchar` and `text` in some newer tables, but when running `appwrite pull tables && appwrite types ./src/li...