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

33 messages · Page 1 of 1 (latest)

outer loom
#

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 idfordb.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);

},
});

@grave saffron bro check this out.

outer loom
#

@valid fjord can you please take a look?

grave saffron
#

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

outer loom
grave saffron
#

No problem

#

I'm betting we'll get some info by seeing what value is being returned from auth.getUserId

outer loom
#

on it

outer loom
#

Don't worry about the id it's just a random gmail

#

[CONVEX Q(currentUser:currentUser)] [LOG] 32

#

this is the length

grave saffron
#

Can you share the updated function source with the log

#

Want to see at what point the log is being printed

outer loom
#

The current User function?

grave saffron
#

Yes, assuming that's where you're logging from

outer loom
#

If I change it from ConvexAuthNextjsProvider ConvexAuthProvider

#

Everything works fine

grave saffron
#

Yep, I understand that

outer loom
#

I think it's working now haha

#

No more error

grave saffron
#

Do you know what changed

outer loom
#

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);

},
});

outer loom
grave saffron
#

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.