
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:
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:
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 User
useEffect(() => {
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]);

Hmm ya I guess it is a little weird. The oauth2 flow creates one event. Then, the create session creates another event
Recommended threads
- what is the best way to redirect a prett...
I tried to do this in a function, but after redirecting to the bucket and try to play video, i get CORS error: The 'Access-Control-Allow-Origin' header has a va...
- why the createOAuth2Token method does no...
I need it to get secret and key, how to get in flutter code?
- Can't download a file through the AppWri...
Heya! SO I am learning backend using Node.js. I am using AppWrite for storage, and in the application I want the files to be downloaded, which are stored by the...
