Skip to content
Back

I cannot make OAuth 2 work

  • 1
  • Auth
  • Web
xSenny_
19 Dec, 2024, 10:54

So I create a session using this code: js export const loginOauth = () => { account.createOAuth2Session(OAuthProvider.Google, 'http://localhost:5173/redirect', 'http://localhost:5173/error') } and then after the user gets redirected, I want to save his data in the database, using this function: ```js export const checkSession = async () => { try { const s = await account.getSession('current'); console.log("Session:", s); return s; } catch (error) { console.error("No active session found:", error); throw error; } };

export const saveAccount = async () => { const s = await checkSession();

try { await database.getDocument('database', 'users', s.userId); } catch { const a = await account.get() await database.createDocument('database', 'users', s.userId, { name: a.name, email: a.email, recovery: '' }, [read("any")])

} }``` in return I get these errors, any sugestions what I might be doing wrong? The accounts are actually created on the platform

TL;DR
Developers are trying to use OAuth2 in their code, but they are facing issues when trying to save user data in the database after redirection. The error suggests there might not be an active session found. A suggestion would be to check the session creation and storage process to ensure it is properly implemented.
xSenny_
19 Dec, 2024, 10:55

All of the functions are also in the same file, if this might be the cause

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more