Danny I
Danny Iā€¢4mo ago

How to check which user is signed in

Sorry all, I just can't find it in the docs. I found an article but the method shown is now deprecated. I'm using the convex auth implementation in react/expo, I assumed there would be a hook for the current user? šŸ™‡šŸ»ā€ā™‚ļø
3 Replies
Convex Bot
Convex Botā€¢4mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Ask in the <#1228095053885476985> channel to get a response from <@1072591948499664996>. - Avoid tagging staff unless specifically instructed. Thank you!
jamalsoueidan
jamalsoueidanā€¢4mo ago
you create a function in the backend
export const currentUser = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
return userId !== null ? ctx.db.get(userId) : null;
},
});
export const currentUser = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
return userId !== null ? ctx.db.get(userId) : null;
},
});
frontend:
const user = useQuery(api.auth.currentUser);
const user = useQuery(api.auth.currentUser);
Danny I
Danny IOPā€¢4mo ago
Thank you so much!

Did you find this page helpful?