Skip to content

Commit 99c9021

Browse files
authored
Signup Customisation [RFC] (#1395)
1 parent cb88dfc commit 99c9021

File tree

69 files changed

+1469
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1469
-196
lines changed

waspc/ChangeLog.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,72 @@
22

33
## 0.11.4
44

5+
### 🎉 [New Feature] Signup Fields Customization
6+
7+
We added an API for extending the default signup form with custom fields. This allows you to add fields like `age`, `address`, etc. to your signup form.
8+
9+
You first need to define the `auth.signup.additionalFields` property in your `.wasp` file:
10+
```wasp
11+
app crudTesting {
12+
// ...
13+
auth: {
14+
userEntity: User,
15+
methods: {
16+
usernameAndPassword: {},
17+
},
18+
onAuthFailedRedirectTo: "/login",
19+
signup: {
20+
additionalFields: import { fields } from "@server/auth.js",
21+
},
22+
},
23+
}
24+
```
25+
26+
Then, you need to define the `fields` object in your `auth.js` file:
27+
```js
28+
import { defineAdditionalSignupFields } from '@wasp/auth/index.js'
29+
30+
export const fields = defineAdditionalSignupFields({
31+
address: (data) => {
32+
// Validate the address field
33+
if (typeof data.address !== 'string') {
34+
throw new Error('Address is required.')
35+
}
36+
if (data.address.length < 10) {
37+
throw new Error('Address must be at least 10 characters long.')
38+
}
39+
// Return the address field
40+
return data.address
41+
},
42+
})
43+
```
44+
45+
Finally, you can extend the `SignupForm` component on the client:
46+
```jsx
47+
import { SignupForm } from "@wasp/auth/forms/Signup";
48+
49+
export const SignupPage = () => {
50+
return (
51+
<div className="container">
52+
<main>
53+
<h1>Signup</h1>
54+
<SignupForm
55+
additionalFields={[
56+
{
57+
name: "address",
58+
label: "Address",
59+
type: "input",
60+
validations: {
61+
required: "Address is required",
62+
},
63+
},
64+
]}
65+
/>
66+
</main>
67+
</div>
68+
);
69+
};
70+
```
571
### 🎉 [New Feature] Support for PostgreSQL Extensions
672

773
Wasp now supports PostgreSQL extensions! You can enable them in your `main.wasp` file:

waspc/data/Generator/templates/react-app/src/auth/forms/Auth.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type State,
88
type CustomizationOptions,
99
type ErrorMessage,
10+
type AdditionalSignupFields,
1011
} from './types'
1112
import { LoginSignupForm } from './internal/common/LoginSignupForm'
1213
import { MessageError, MessageSuccess } from './internal/Message'
@@ -39,9 +40,11 @@ export const AuthContext = createContext({
3940
setSuccessMessage: (successMessage: string | null) => {},
4041
})
4142

42-
function Auth ({ state, appearance, logo, socialLayout = 'horizontal' }: {
43+
function Auth ({ state, appearance, logo, socialLayout = 'horizontal', additionalSignupFields }: {
4344
state: State;
44-
} & CustomizationOptions) {
45+
} & CustomizationOptions & {
46+
additionalSignupFields?: AdditionalSignupFields;
47+
}) {
4548
const [errorMessage, setErrorMessage] = useState<ErrorMessage | null>(null);
4649
const [successMessage, setSuccessMessage] = useState<string | null>(null);
4750
const [isLoading, setIsLoading] = useState(false);
@@ -82,6 +85,7 @@ function Auth ({ state, appearance, logo, socialLayout = 'horizontal' }: {
8285
<LoginSignupForm
8386
state={state}
8487
socialButtonsDirection={socialButtonsDirection}
88+
additionalSignupFields={additionalSignupFields}
8589
/>
8690
)}
8791
{=# isEmailAuthEnabled =}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import Auth from './Auth'
2-
import { type CustomizationOptions, State } from './types'
2+
import {
3+
type CustomizationOptions,
4+
type AdditionalSignupFields,
5+
State,
6+
} from './types'
37

48
export function SignupForm({
59
appearance,
610
logo,
711
socialLayout,
8-
}: CustomizationOptions) {
12+
additionalFields,
13+
}: CustomizationOptions & { additionalFields?: AdditionalSignupFields; }) {
914
return (
1015
<Auth
1116
appearance={appearance}
1217
logo={logo}
1318
socialLayout={socialLayout}
1419
state={State.Signup}
20+
additionalSignupFields={additionalFields}
1521
/>
1622
)
1723
}

waspc/data/Generator/templates/react-app/src/auth/forms/internal/Form.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export const FormLabel = styled('label', {
1414
display: 'block',
1515
fontSize: '$sm',
1616
fontWeight: '500',
17+
marginBottom: '0.5rem',
1718
})
1819

19-
export const FormInput = styled('input', {
20+
const commonInputStyles = {
2021
display: 'block',
2122
lineHeight: '1.5rem',
2223
fontSize: '$sm',
@@ -44,7 +45,18 @@ export const FormInput = styled('input', {
4445
paddingBottom: '0.375rem',
4546
paddingLeft: '0.75rem',
4647
paddingRight: '0.75rem',
48+
margin: 0,
49+
}
4750

51+
export const FormInput = styled('input', commonInputStyles)
52+
53+
export const FormTextarea = styled('textarea', commonInputStyles)
54+
55+
export const FormError = styled('div', {
56+
display: 'block',
57+
fontSize: '$sm',
58+
fontWeight: '500',
59+
color: '$formErrorText',
4860
marginTop: '0.5rem',
4961
})
5062

0 commit comments

Comments
 (0)