RQ
RQ2w ago

Web3auth

Having issues with web3auth and convex i have setup the client provider as such
"use client";

import { useAuthFromWeb3Auth } from "@/hooks/useAuthFromWeb3Auth";
import { ConvexProviderWithAuth } from "convex/react";
import { ConvexReactClient } from "convex/react";
import { ReactNode } from "react";

const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!);

export default function ConvexClientProvider({
children,
}: {
children: ReactNode;
}) {
return (
<ConvexProviderWithAuth client={convex} useAuth={useAuthFromWeb3Auth}>
{children}
</ConvexProviderWithAuth>
);
}
"use client";

import { useAuthFromWeb3Auth } from "@/hooks/useAuthFromWeb3Auth";
import { ConvexProviderWithAuth } from "convex/react";
import { ConvexReactClient } from "convex/react";
import { ReactNode } from "react";

const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!);

export default function ConvexClientProvider({
children,
}: {
children: ReactNode;
}) {
return (
<ConvexProviderWithAuth client={convex} useAuth={useAuthFromWeb3Auth}>
{children}
</ConvexProviderWithAuth>
);
}
my useAuth is
import { useCallback, useMemo } from "react";
import { useIdentityToken, useWeb3Auth } from "@web3auth/modal/react";

export function useAuthFromWeb3Auth() {
const { getIdentityToken, loading, token } = useIdentityToken();
const { isConnected, isInitialized } = useWeb3Auth();

const fetchAccessToken = useCallback(
async ({ forceRefreshToken = false }: { forceRefreshToken?: boolean } = {}) => {
try {
if (!isInitialized || !isConnected) return "";

let identityToken = token;

if (!identityToken || forceRefreshToken) {
identityToken = await getIdentityToken();
}
return identityToken ?? "";
} catch (err) {
console.error("Error fetching Web3Auth identity token:", err);
return "";
}
},
[isInitialized, isConnected, token, getIdentityToken]
);

return useMemo(
() => ({
isLoading: !isInitialized || loading,
isAuthenticated: isInitialized && isConnected,
fetchAccessToken,
}),
[loading, isInitialized, isConnected, fetchAccessToken]
);
}
import { useCallback, useMemo } from "react";
import { useIdentityToken, useWeb3Auth } from "@web3auth/modal/react";

export function useAuthFromWeb3Auth() {
const { getIdentityToken, loading, token } = useIdentityToken();
const { isConnected, isInitialized } = useWeb3Auth();

const fetchAccessToken = useCallback(
async ({ forceRefreshToken = false }: { forceRefreshToken?: boolean } = {}) => {
try {
if (!isInitialized || !isConnected) return "";

let identityToken = token;

if (!identityToken || forceRefreshToken) {
identityToken = await getIdentityToken();
}
return identityToken ?? "";
} catch (err) {
console.error("Error fetching Web3Auth identity token:", err);
return "";
}
},
[isInitialized, isConnected, token, getIdentityToken]
);

return useMemo(
() => ({
isLoading: !isInitialized || loading,
isAuthenticated: isInitialized && isConnected,
fetchAccessToken,
}),
[loading, isInitialized, isConnected, fetchAccessToken]
);
}
10 Replies
Convex Bot
Convex Bot2w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
RQ
RQOP4d ago
and i verified that i can see the JWT token from identitytoken on the console log i have setup the auth.config.ts
export default {
providers: [
{
domain: "https://api-auth.web3auth.io",
applicationID: "my-web3auth-client-id",
},
],
};
export default {
providers: [
{
domain: "https://api-auth.web3auth.io",
applicationID: "my-web3auth-client-id",
},
],
};
but i always get null here
2025-08-15, 5:54:14 a.m. [CONVEX Q(users:getCurrentUser)] [LOG] null
2025-08-15, 5:54:14 a.m. [CONVEX Q(users:getCurrentUser)] [LOG] null
import { query } from "./_generated/server";

export const getCurrentUser = query({
args: {},
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity();
console.log(identity)
if (!identity) {
return null;
}

return {
tokenIdentifier: identity.tokenIdentifier,
subject: identity.subject,
email: identity.email,
name: identity.name,
};
},
});
import { query } from "./_generated/server";

export const getCurrentUser = query({
args: {},
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity();
console.log(identity)
if (!identity) {
return null;
}

return {
tokenIdentifier: identity.tokenIdentifier,
subject: identity.subject,
email: identity.email,
name: identity.name,
};
},
});
Also what provider would i use here since its Generic OIDC
import { Password } from "@convex-dev/auth/providers/Password";
import { convexAuth } from "@convex-dev/auth/server";

export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
providers: [Password],
});
import { Password } from "@convex-dev/auth/providers/Password";
import { convexAuth } from "@convex-dev/auth/server";

export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
providers: [Password],
});
@Nicolas this is my ticket- thought it was lol but i can open a ticket from dashboard
Hakkā 多
Hakkā 多4d ago
Hi, your aim is to keep a trace of connected wallets in your convex auth db? Personnaly I'm using web3 auth with wagmi x reown and I'm getting auth states from wagmi hooks
Hakkā 多
Hakkā 多4d ago
Else you have wagmi x web3 auth setup here https://web3auth.io/docs/quick-start?framework=REACT&stepIndex=2
Web3Auth
Integration Builder
Web3Auth Integration Builder for easy quick start. Web3Auth is simple, non-custodial auth infrastructure that enables Web3 wallets and applications to provide seamless user logins for both mainstream and native Web3 users.
RQ
RQOP3d ago
My goal is to have the user authed on the backend when they login / connect their wallet
Hakkā 多
Hakkā 多3d ago
I see the point, I'm trying to achieve the same goal this week but looks a bit complex :3
Nicolas
Nicolas3d ago
If you're a pro user yes, please open a ticket from the dashboard, it will be easier for us to handle it
Hakkā 多
Hakkā 多3d ago
Maybe you can use w/nextauth x siwx, I found a good example here https://github.com/reown-com/appkit/blob/main/apps/laboratory/src/utils/auth.ts
GitHub
appkit/apps/laboratory/src/utils/auth.ts at main · reown-com/appkit
The full stack toolkit to build onchain app UX. Contribute to reown-com/appkit development by creating an account on GitHub.
RQ
RQOP3d ago
i could do it another way but i thought convex has a streamlined way to get it working with their setup also i cant use reown as it doesnt work in PWA mode
Hakkā 多
Hakkā 多3d ago
i got something it look like i cannot upload file here look at your dm

Did you find this page helpful?