
This function fails to save the user to the DB after login:
TypeScript
export async function loginUsingGoogle() {
await account.createOAuth2Session(
OAuthProvider.Google,
"http://localhost:3000/verification",
"http://localhost:3000/sign-in"
);
const user = await account.get();
try {
await databases.getDocument("development", "users", user.$id);
} catch {
const imageUrl = avatar.getInitials(user.name);
await databases.createDocument("development", "users", user.$id, {
email: user.email,
name: user.name,
imageUrl,
});
}
}
I'm assuming the reason for that is that the page gets redirected to the external auth page. So how do I add a user to the DB after a successful login?
TL;DR
The function to save the user to the DB after OAuth login is failing due to redirection to the external auth page. To resolve this, consider updating the code flow to handle the successful login scenario after the redirection. This could involve implementing a callback function or handling the user creation logic after successful authentication.Recommended threads
- Error getting session: AppwriteException...
I get this error `Error getting session: AppwriteException: User (role: guests) missing scope (account)` when running in prod. As soon as I try running my app o...
- OTP Session template not working and is ...
Okay so it has been a long while with the issue with OTP Session template, and currently I tried self-hosting and found out that it is linked with Verification ...
- CORS and 401 Unauthorized Issues on Appw...
I'm developing a frontend app using the Appwrite Web SDK on http://localhost:3000, and I'm encountering two issues when trying to register or log in users: COR...
