Priyanka
Priyanka5mo ago

when to use getUserIdentity() and getAuthUserId()?

When to use these ?
4 Replies
Priyanka
PriyankaOP5mo ago
I am using Github for authentication using convex auth. When the authentication is done, there is a new link generated as http://localhost:8501/?code=37378399. When I used the mutation function as provided here https://docs.convex.dev/auth/database-auth#mutation-for-storing-current-user. I get the identity as null and the below error: [LOG] 'Identity:' null [ERROR] 'Error in mutation handler:' [Error: Called storeUser without authentication present or missing email] Error checking user authentication: [Request ID: 2be5d9e1e54f7137] Server Error Uncaught Error: Called storeUser without authentication present or missing email Could anyone help to resolve this ? Thank you!
Storing Users in the Convex Database | Convex Developer Hub
_If you're using Convex Auth the user information
Priyanka
PriyankaOP5mo ago
The SITE_URL is configured as http://localhost:8501 What is the process used in convex side after the authentication is done in github, do we need to write a code to get the access token from the code which is present in the url ?
sshader
sshader5mo ago
What information are you trying to store about the user? Sounds like you are using Convex Auth, so note that the top of the doc you link says "If you're using Convex Auth the user information is already stored in your database. There's nothing else you need to implement." If you're trying to customize what information gets stored about the user, check out https://labs.convex.dev/auth/setup/schema#customizing-the-users-table
Customizing Schema - Convex Auth
Authentication library for your Convex backend
Priyanka
PriyankaOP5mo ago
I need to retreive the user_id from the users table, but when I use the mutation, I get it as null instead of the user_id. it says the client is not authenticated import { mutation } from "../_generated/server"; import { getAuthUserId } from "@convex-dev/auth/server"; export const doSomething = mutation({ args: {/* ... */}, handler: async (ctx, args) => { const userId = await getAuthUserId(ctx); if (userId === null) { throw new Error("Client is not authenticated!") } const user = await ctx.db.get(userId); // ... }, }); This is the mutation function directly taken from the documentation

Did you find this page helpful?