© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3mo ago•
8 replies
Boomilei

exchangeCodeForSession not working

authSolved🟡javascript
Why can I not create a session with that code. I've tried everything. Someone please help me.

Example url: http://localhost:3000/reset-password?code=558dd56e-417a-4c42-a7a7-43b8d978f765

AuthApiError: invalid request: both auth code and code verifier should be non-empty
at handleError (fetch.ts:102:9)
at async _handleRequest (fetch.ts:195:5)
at async _request (fetch.ts:157:16)
at async SupabaseAuthClient._exchangeCodeForSession (GoTrueClient.ts:868:31)

    const handleCode = async () => {
        try {
            const code = searchParams.get("code");
            console.log("code", code);

            const { data, error } = await supabaseBrowserClient.auth.exchangeCodeForSession(code);
            console.log(data, error);

            if (error) throw error;
            setLoading(false);
        } catch (error) {
            console.log("Failed to make session");

            console.log(error);
        }
    };

    useEffect(() => {
        handleCode();
    }, []);
    const handleCode = async () => {
        try {
            const code = searchParams.get("code");
            console.log("code", code);

            const { data, error } = await supabaseBrowserClient.auth.exchangeCodeForSession(code);
            console.log(data, error);

            if (error) throw error;
            setLoading(false);
        } catch (error) {
            console.log("Failed to make session");

            console.log(error);
        }
    };

    useEffect(() => {
        handleCode();
    }, []);



export async function resetUserPasswordByID(userID, eMail) {
    try {
        await requirePermission(process.env.ADMIN_PERMISSION_ID);
        const supabaseClient = await createClient();
        await supabaseClient.auth.admin.updateUserById(userID, {
            user_metadata: { password_set: false },
            password: v4(),
        });
        await supabaseClient.auth.resetPasswordForEmail(eMail, {
            redirectTo: "http://localhost:3000/reset-password",
        });

        revalidatePath("/admin/users");
    } catch (error) {
        console.log(error);
        throw new Error("Failed to reset user password");
    }
}
export async function resetUserPasswordByID(userID, eMail) {
    try {
        await requirePermission(process.env.ADMIN_PERMISSION_ID);
        const supabaseClient = await createClient();
        await supabaseClient.auth.admin.updateUserById(userID, {
            user_metadata: { password_set: false },
            password: v4(),
        });
        await supabaseClient.auth.resetPasswordForEmail(eMail, {
            redirectTo: "http://localhost:3000/reset-password",
        });

        revalidatePath("/admin/users");
    } catch (error) {
        console.log(error);
        throw new Error("Failed to reset user password");
    }
}
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Unable to exchangeCodeForSession
SupabaseSSupabase / help-and-questions
3w ago
Session from `supabase.auth.exchangeCodeForSession()` not persisting
SupabaseSSupabase / help-and-questions
3y ago
exchangeCodeForSession doesn´t work in production
SupabaseSSupabase / help-and-questions
14mo ago
Supabase.auth.exchangeCodeForSession doesn't persist session
SupabaseSSupabase / help-and-questions
3y ago