Devben
Devben6mo ago

convex auth: Unable to decode ID: Invalid ID length 5

I'm trying to get the current user but it's returning undefine am using nextjs and i follow the nextjs step, but when i change the convexnextjsauthprovide to authprovider i see the user however am seeing this error. Uncaught (in promise) Error: [Request ID: 5dfe7ffe2f531b80] Server Error Uncaught Error: Uncaught Error: Invalid argument id for db.get: Unable to decode ID: Invalid ID length 5 my current user function import { query } from "./_generated/server"; import { auth } from "./auth"; export const currentUser = query({ args: {}, handler: async (ctx) => { const userId = await auth.getUserId(ctx);
if (userId === null || userId.length < 5) { console.log("Invalid user ID"); return null; } return await ctx.db.get(userId); }, }); @erquhart bro check this out.
16 Replies
Devben
DevbenOP6mo ago
@jamwt can you please take a look?
erquhart
erquhart6mo ago
Please avoid at-mentioning people to get an answer. Can you log the 5 character id string and share it here Clearly not a real id
Devben
DevbenOP6mo ago
oh! am sorry
erquhart
erquhart6mo ago
No problem I'm betting we'll get some info by seeing what value is being returned from auth.getUserId
Devben
DevbenOP6mo ago
on it
Devben
DevbenOP6mo ago
No description
Devben
DevbenOP6mo ago
Don't worry about the id it's just a random gmail [CONVEX Q(currentUser:currentUser)] [LOG] 32 this is the length
erquhart
erquhart6mo ago
Can you share the updated function source with the log Want to see at what point the log is being printed
Devben
DevbenOP6mo ago
The current User function?
erquhart
erquhart6mo ago
Yes, assuming that's where you're logging from
Devben
DevbenOP6mo ago
Just to let you know If I change it from ConvexAuthNextjsProvider ConvexAuthProvider Everything works fine
erquhart
erquhart6mo ago
Yep, I understand that
Devben
DevbenOP6mo ago
Hey hold on bro I think it's working now haha No more error
erquhart
erquhart6mo ago
Do you know what changed
Devben
DevbenOP6mo ago
Nope I try to refresh and seeing this [CONVEX Q(currentUser:currentUser)] [LOG] undefined logging.js:37 [CONVEX Q(currentUser:currentUser)] [LOG] null logging.js:37 [CONVEX Q(currentUser:currentUser)] [LOG] 'Invalid user ID' nothing in convex log import { query } from "./_generated/server"; import { auth } from "./auth"; export const currentUser = query({ args: {}, handler: async (ctx) => { const userId = await auth.getUserId(ctx); const length = userId?.length; console.log(length); console.log(userId); if (userId === null || userId.length <= 5) { console.log("Invalid user ID"); return null; } return await ctx.db.get(userId); }, }); Now when I logout and logIn am seeing same thing
erquhart
erquhart6mo ago
What is logging when it fails Including from the loggers that were just added You're not going to log a string with length 32, and then call ctx.db.get on the next line and get an error that the string has length 5. Missing something here.

Did you find this page helpful?