bear
bear3mo ago

How do I authenticate a query?

I'm trying to use convex-auth in svelte, I'm retreiving the accessToken as follows, this gives me a token and a refreshToken
const tokens = await client.action(api.auth.signIn, {
provider: 'password',
params: {
flow: 'signIn',
email,
password
}
});
const tokens = await client.action(api.auth.signIn, {
provider: 'password',
params: {
flow: 'signIn',
email,
password
}
});
however when trying to retrieve the current user, through const me = await client.query(api.users.currentUser, {}); for the API
export const currentUser = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
if (userId === null) {
return null;
}
return await ctx.db.get(userId);
}
});
export const currentUser = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
if (userId === null) {
return null;
}
return await ctx.db.get(userId);
}
});
it always returns null
3 Replies
Convex Bot
Convex Bot3mo 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. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
sshader
sshader3mo ago
The token needs to be hooked up to the Convex client via the client.setAuth method. I'm not super familiar with Svelte, but here's how the React set up works: https://github.com/get-convex/convex-js/blob/58dc97eebb608de28e0c39ae00c5beadc63773b7/src/react/ConvexAuthState.tsx#L151
GitHub
convex-js/src/react/ConvexAuthState.tsx at 58dc97eebb608de28e0c39ae...
TypeScript/JavaScript client library for Convex. Contribute to get-convex/convex-js development by creating an account on GitHub.
bear
bearOP3mo ago
thank you for anyone reading, if client.setAuth is throwing errors, odds are you've misconfigured your JWKS env var

Did you find this page helpful?