Skip to content

Commit

Permalink
feat(core,antd,mui,mantine,chakra-uş): add new prop to auth-page to p…
Browse files Browse the repository at this point in the history
…ass extra params to auth-provider
  • Loading branch information
alicanerdurmaz committed Oct 25, 2024
1 parent 6d224d0 commit b336066
Show file tree
Hide file tree
Showing 35 changed files with 636 additions and 20 deletions.
45 changes: 45 additions & 0 deletions .changeset/breezy-wolves-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
"@refinedev/chakra-ui": minor
"@refinedev/mantine": minor
"@refinedev/antd": minor
"@refinedev/core": minor
"@refinedev/mui": minor
---

feat: added new prop called `mutationVariables` to `<AuthPage />`. #6431
From now on, you can pass additional parameters to the `authProvider` methods using the `mutationVariables` prop of the `<AuthPage />` component.

```tsx
import { AuthPage } from "@refinedev/antd"; // or "@refinedev/chakra-ui", "@refinedev/mantine", "@refinedev/mui"

const MyLoginPage = () => {
return (
<AuthPage
type="login" // all other types are also supported.
// highlight-start
mutationVariables={{
foo: "bar",
xyz: "abc",
}}
// highlight-end
/>
);
};

// all mutation methods are supported.
const authProvider = {
login: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
register: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
// ...
};
```

[Resolves #6431](https://github.com/refinedev/refine/issues/6431)
35 changes: 35 additions & 0 deletions documentation/docs/authentication/components/auth-page/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,41 @@ const MyLoginPage = () => {
};
```

### mutationVariables

`mutationVariables` is used to pass additional variables to the `authProvider` methods.

```tsx
const MyLoginPage = () => {
return (
<AuthPage
type="login" // all other types are also supported.
// highlight-start
mutationVariables={{
foo: "bar",
xyz: "abc",
}}
// highlight-end
/>
);
};

// all mutation methods are supported.
const authProvider = {
login: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
register: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
// ...
};
```

## API Reference

### Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,41 @@ const MyLoginPage = () => {
};
```

### mutationVariables

`mutationVariables` is used to pass additional variables to the `authProvider` methods.

```tsx
const MyLoginPage = () => {
return (
<AuthPage
type="login" // all other types are also supported.
// highlight-start
mutationVariables={{
foo: "bar",
xyz: "abc",
}}
// highlight-end
/>
);
};

// all mutation methods are supported.
const authProvider = {
login: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
register: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
// ...
};
```

## FAQ

### How can I remove the default title and logo ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,41 @@ const MyLoginPage = () => {
};
```

### mutationVariables

`mutationVariables` is used to pass additional variables to the `authProvider` methods.

```tsx
const MyLoginPage = () => {
return (
<AuthPage
type="login" // all other types are also supported.
// highlight-start
mutationVariables={{
foo: "bar",
xyz: "abc",
}}
// highlight-end
/>
);
};

// all mutation methods are supported.
const authProvider = {
login: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
register: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
// ...
};
```

## API Reference

### Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,41 @@ const MyLoginPage = () => {
};
```

### mutationVariables

`mutationVariables` is used to pass additional variables to the `authProvider` methods.

```tsx
const MyLoginPage = () => {
return (
<AuthPage
type="login" // all other types are also supported.
// highlight-start
mutationVariables={{
foo: "bar",
xyz: "abc",
}}
// highlight-end
/>
);
};

// all mutation methods are supported.
const authProvider = {
login: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
register: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
// ...
};
```

## API Reference

### Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,43 @@ const MyLoginPage = () => {
};
```

### mutationVariables

`mutationVariables` is used to pass additional variables to the `authProvider` methods.

```tsx
import { AuthPage } from "@refinedev/mui";

const MyLoginPage = () => {
return (
<AuthPage
type="login" // all other types are also supported.
// highlight-start
mutationVariables={{
foo: "bar",
xyz: "abc",
}}
// highlight-end
/>
);
};

// all mutation methods are supported.
const authProvider = {
login: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
register: async ({ foo, xyz, ...otherProps }) => {
console.log(foo); // bar
console.log(xyz); // abc
// ...
},
// ...
};
```

## API Reference

### Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ForgotPasswordPage: React.FC<ResetPassworProps> = ({
renderContent,
formProps,
title,
mutationVariables,
}) => {
const { token } = theme.useToken();
const [form] = Form.useForm<ForgotPasswordFormTypes>();
Expand Down Expand Up @@ -104,7 +105,9 @@ export const ForgotPasswordPage: React.FC<ResetPassworProps> = ({
<Form<ForgotPasswordFormTypes>
layout="vertical"
form={form}
onFinish={(values) => forgotPassword(values)}
onFinish={(values) =>
forgotPassword({ ...values, ...mutationVariables })
}
requiredMark={false}
{...formProps}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const LoginPage: React.FC<LoginProps> = ({
formProps,
title,
hideForm,
mutationVariables,
}) => {
const { token } = theme.useToken();
const [form] = Form.useForm<LoginFormTypes>();
Expand Down Expand Up @@ -111,6 +112,7 @@ export const LoginPage: React.FC<LoginProps> = ({
}}
onClick={() =>
login({
...mutationVariables,
providerName: provider.name,
})
}
Expand Down Expand Up @@ -152,7 +154,7 @@ export const LoginPage: React.FC<LoginProps> = ({
<Form<LoginFormTypes>
layout="vertical"
form={form}
onFinish={(values) => login(values)}
onFinish={(values) => login({ ...values, ...mutationVariables })}
requiredMark={false}
initialValues={{
remember: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
formProps,
title,
hideForm,
mutationVariables,
}) => {
const { token } = theme.useToken();
const [form] = Form.useForm<RegisterFormTypes>();
Expand Down Expand Up @@ -108,6 +109,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
}}
onClick={() =>
register({
...mutationVariables,
providerName: provider.name,
})
}
Expand Down Expand Up @@ -152,7 +154,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
<Form<RegisterFormTypes>
layout="vertical"
form={form}
onFinish={(values) => register(values)}
onFinish={(values) => register({ ...mutationVariables, ...values })}
requiredMark={false}
{...formProps}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
renderContent,
formProps,
title,
mutationVariables,
}) => {
const { token } = theme.useToken();
const [form] = Form.useForm<UpdatePasswordFormTypes>();
Expand Down Expand Up @@ -96,7 +97,9 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
<Form<UpdatePasswordFormTypes>
layout="vertical"
form={form}
onFinish={(values) => updatePassword(values)}
onFinish={(values) =>
updatePassword({ ...values, ...mutationVariables })
}
requiredMark={false}
{...formProps}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
renderContent,
formProps,
title,
mutationVariables,
}) => {
const { onSubmit, ...useFormProps } = formProps || {};
const { mutate } = useForgotPassword<ForgotPasswordFormTypes>();
Expand Down Expand Up @@ -99,7 +100,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
return onSubmit(data);
}

return mutate(data);
return mutate({ ...mutationVariables, ...data });
})}
>
<FormControl mb="3" isInvalid={!!errors?.email}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const LoginPage: React.FC<LoginProps> = ({
formProps,
title,
hideForm,
mutationVariables,
}) => {
const { onSubmit, ...useFormProps } = formProps || {};

Expand Down Expand Up @@ -86,6 +87,7 @@ export const LoginPage: React.FC<LoginProps> = ({
fontSize="sm"
onClick={() =>
login({
...mutationVariables,
providerName: provider.name,
})
}
Expand Down Expand Up @@ -142,7 +144,7 @@ export const LoginPage: React.FC<LoginProps> = ({
return onSubmit(data);
}

return login(data);
return login({ ...mutationVariables, ...data });
})}
>
<FormControl mt="6" isInvalid={!!errors?.email}>
Expand Down
Loading

0 comments on commit b336066

Please sign in to comment.