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
- 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...