Web3auth
Having issues with web3auth and convex
i have setup the client provider as such
my useAuth is
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]
);
}