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.
if (userId === null || userId.length < 5) { console.log("Invalid user ID"); return null; } return await ctx.db.get(userId); }, }); @erquhart bro check this out.
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
@jamwt can you please take a look?
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
oh! am sorry
No problem
I'm betting we'll get some info by seeing what value is being returned from
auth.getUserId
on it
Don't worry about the id it's just a random gmail
[CONVEX Q(currentUser:currentUser)] [LOG] 32
this is the length
Can you share the updated function source with the log
Want to see at what point the log is being printed
The current User function?
Yes, assuming that's where you're logging from
Just to let you know
If I change it from ConvexAuthNextjsProvider ConvexAuthProvider
Everything works fine
Yep, I understand that
Hey hold on bro
I think it's working now haha
No more error
Do you know what changed
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
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.