Los FelizOriginal post
Rank 2: Process
should every user login via OAuth2 create two instances of session.create in the Activity tab? When I login, only one instance of session gets created in the Sessions tab, but I see that two events of session.create was called. Is that how it should be?
my code for user auth:
JavaScript
export const googleOAuthLogin = async () => { try { const baseUrl = window.location.origin
const userAccount = account.createOAuth2Token( 'google', `${baseUrl}/user/me`, `${baseUrl}/`, )
console.log('Success logging in with Google:', userAccount);
} catch (error) { console.error('Error logging in with google:', error); }}
export const handleOAuthSession = async (userId, secret) => {
try { await account.createSession(userId, secret); const user = await account.get(); return user; } catch (error) { console.error('Authentication failed:', error); throw error; }};This is Me.jsx:
JavaScript
useEffect(() => { const checkingSessionStatus = async () => { try { const usr = await getAccount(); if (usr) { console.log('Session in progress.'); setIsSessionInProgress(true); setUser(usr); } else {setIsSessionInProgress(false);}} catch (error) {console.error(error);}};checkingSessionStatus();}, [])
//Authenticating UseruseEffect(() => {const params = new URLSearchParams(window.location.search);const userId = params.get('userId');const secret = params.get('secret');const authenticateUser = async () => {if (hasAuthenticated.current !userId !secret) return;hasAuthenticated.current = true;try { const authenticatedUser = await handleOAuthSession(userId, secret); setUser(authenticatedUser);} catch (err) { console.error(err);}};if (!isSessionInProgress) authenticateUser();}, [isSessionInProgress]);Summary
Developers are trying to figure out if every user login via OAuth2 should create two instances of `session.create` in the Activity tab, as they are seeing double the events being called. The code provided indicates that one event is created during the oauth2 flow and another during session creation. The issue seems to be related to how the code is handling session creation and authentication.
Solution: The problem might stem from how `userAccount` is being handled in `googleOAuthLogin`, ensuring that `baseUrl` is set correctly might resolve the discrepancy in event creation. Also, reviewing the logic in `handleOAuthSession` and `Me.jsx`