Trouble with getUserIdentity(), Auth0 and Next.js
Method 1 - ConvexProviderWithAuth0, @auth0/auth0-react
I followed Auth0 with Convex tutorial for this one. The problem is @auth0/auth0-react will not work with Next.js (even with client side render).
Method 2 - ConvexProviderWithAuth and @auth0/nextjs-auth0
I installed @auth0/nextjs-auth0 and followed Auth0's official tutorial. I am now able to authenticate within the app.... but when I use
ConvexProviderWithAuth0 from convex/react-auth0, ctx.auth.getUserIdentity() only ever returns {isLoading:true,isAuthenticated:false}. I then tried
ConvexProviderWithAuth from convex/react and hard coded the useAuth prop:/context/ConvexProvider.tsx
"use client";
import { ReactNode } from "react";
import { ConvexProviderWithAuth, ConvexReactClient } from "convex/react";
import { useUser } from "@auth0/nextjs-auth0/client";
const convex = new ConvexReactClient (process. env.NEXT_PUBLIC_CONVEX _URL!) ;
export default function ConvexClientProvider({children}) {
const { user, isLoading } = useUser();
return (
<ConvexProviderWithAuth
client={convex}
useAuth={() => {
return {
isLoading,
isAuthenticated: !!user,
fetchAccessToken,
};
}}
>
{children}
</ConvexProviderWithAuth>
);
}
const fetchAccessToken = async (args: { forceRefreshToken: boolean }) => {
return "eyJ...WLw";
}Even with a hardcoded response to the useAuth hook (which fixes the perpetual loading problem) for the ConvexProviderWithAuth,
ctx.auth.getUserIdentity() just returns null.Tutorial:
Auth0 with Convex - https://docs.convex.dev/auth/auth0
Auth0 with Next.js (@auth0/nextjs-auth0) - https://auth0.com/docs/quickstart/webapp/nextjs/interactive



