cabbage
cabbage8mo ago

using convex auth & nextjs router. using router.back() does not refresh auth in time.

i have a convex & nextjs app. convex api that runs on the main page:
export const get = query({
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
if (userId === null) {
throw new Error("Not signed in");
}
return await ctx.db
.query("notepads")
.filter((q) => q.eq(q.field("userId"), userId))
.order("desc")
.collect();
},
});
export const get = query({
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
if (userId === null) {
throw new Error("Not signed in");
}
return await ctx.db
.query("notepads")
.filter((q) => q.eq(q.field("userId"), userId))
.order("desc")
.collect();
},
});
when i go to a subpage and click the back button to go back to main (via router.back() or router.push()), it gives me this "not signed in error". from console logging, it seems like getAuthUserId is returning null and not updating. it seems to be saving the "is Authenticated" state do you have recommendations?
No description
1 Reply
erquhart
erquhart2mo ago
It looks like "Not signed in" is an error message being thrown by your own application code, Convex doesn't do any auth checks on your behalf. If the query is being called while unauthenticated, you either need to add a client side check for authentication before calling it, or a server side check if the page you're going back to is being server rendered.

Did you find this page helpful?