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
- is `account.get()` safe to be used in th...
I want to user's `id` for authentication. However, a while ago I was told in this server not to use `account.get()` and instead add user preferences for that us...
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- CORS errors in Obsidian custom plugin
Hi, anyone here familiar with obsidian community plugins? In short: it's a local first note app which supports writing your own add-ons / plugin But I keep get...