Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] mutationOptions are overriding Refine's behavior unexpectedly #5888

Open
MohammadxAli opened this issue Apr 24, 2024 · 2 comments · May be fixed by #5889
Open

[BUG] mutationOptions are overriding Refine's behavior unexpectedly #5888

MohammadxAli opened this issue Apr 24, 2024 · 2 comments · May be fixed by #5889
Assignees
Labels
bug Something isn't working

Comments

@MohammadxAli
Copy link

MohammadxAli commented Apr 24, 2024

Describe the bug

Consider this:

import { useLogin } from "@refinedev/core";

const { mutateAsync: login, isLoading } = useLogin({
    mutationOptions: {
        onSuccess(data) {
         console.log("Hey!");
        },
    },
});

And authProvider.ts as follow:

"use client";

import { AuthBindings, HttpError } from "@refinedev/core";

export const authProvider: AuthBindings = {
    login: async ({ username, password }) => {
        try {
            // Preform login
            return { success: true, redirectTo: "/" };
        } catch (error) {
            return {
                success: false,
                error: { message: "Username or password is incorrect", statusCode: (error as HttpError).statusCode },
            };
        }
    },
};

Then onSuccess callback on useLogin will override the Refine's behavior for onSuccess causing the redirectTo to not work.

Steps To Reproduce

  1. Create a login component
  2. Create an authProvider
  3. Add a custom onSuccess callback in useLogin({ mutationOptions: onSuccess() { /* callback */ }});
  4. Redirect doesn't happen after successful login

Expected behavior

mutationOptions should work along side the Refine's default behavior, redirect should occur.

Packages

  • @refinedev/core

Additional Context

No response

@MohammadxAli MohammadxAli added the bug Something isn't working label Apr 24, 2024
@aliemir
Copy link
Member

aliemir commented May 29, 2024

As this can be seen from this line:

mutationOptions?: Omit<
UseMutationOptions<TLoginData, Error | RefineError, TVariables, unknown>,
"mutationFn" | "onError" | "onSuccess"
>;

We're omitting onSuccess handler from the mutationOptions on purpose.

On all other Refine hooks, we've omitted onSuccess, onSettled, onError methods if we're using them in our implementation. If we're going to make them work without breaking the current implementation, we need to apply similar changes to all Refine hooks like in the PR #5889

@rners01
Copy link

rners01 commented May 30, 2024

@aliemir How can one provide redirect after successful mutate if there's no onSuccess anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants