v0.11.4
版本发布时间: 2023-09-12 20:12:33
wasp-lang/wasp最新发布版本:v0.15.2(2024-11-20 03:53:43)
🎉 [New Feature] Signup Fields Customization
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.
You first need to define the auth.signup.additionalFields
property in your .wasp
file:
app crudTesting {
// ...
auth: {
userEntity: User,
methods: {
usernameAndPassword: {},
},
onAuthFailedRedirectTo: "/login",
signup: {
additionalFields: import { fields } from "@server/auth.js",
},
},
}
Then, you need to define the fields
object in your auth.js
file:
import { defineAdditionalSignupFields } from '@wasp/auth/index.js'
export const fields = defineAdditionalSignupFields({
address: (data) => {
// Validate the address field
if (typeof data.address !== 'string') {
throw new Error('Address is required.')
}
if (data.address.length < 10) {
throw new Error('Address must be at least 10 characters long.')
}
// Return the address field
return data.address
},
})
Finally, you can extend the SignupForm
component on the client:
import { SignupForm } from "@wasp/auth/forms/Signup";
export const SignupPage = () => {
return (
<div className="container">
<main>
<h1>Signup</h1>
<SignupForm
additionalFields={[
{
name: "address",
label: "Address",
type: "input",
validations: {
required: "Address is required",
},
},
]}
/>
</main>
</div>
);
};
🎉 [New Feature] Support for PostgreSQL Extensions
Wasp now supports PostgreSQL extensions! You can enable them in your main.wasp
file:
app todoApp {
// ...
db: {
system: PostgreSQL,
prisma: {
clientPreviewFeatures: ["postgresqlExtensions"],
dbExtensions: [{
name: "pgvector",
// map: "vector", (optional)
// schema: "public", (optional)
// version: "0.1.0", (optiona)
}]
}
}
}
This will add the necessary Prisma configuration to your schema.prisma
file. Keep in mind that your database needs to support the extension you want to use. For example, if you want to use the pgvector
extension, you need to install it in your database first.
🎉 [New Feature] Added Typescript support for Jobs
Now you can type your async jobs better and receive all the benefits of Typescript. When you define a job, Wasp will generate a generic type which you can use to type your job function:
job simplePrintJob {
executor: PgBoss,
perform: {
fn: import { simplePrint } from "@server/jobs.js",
},
entities: [Task]
}
import { SimplePrintJob } from "@wasp/jobs/simplePrintJob";
import { Task } from "@wasp/entities";
export const simplePrint: SimplePrintJob<
{ name: string },
{ tasks: Task[] }
> = async (args, context) => {
// 👆 args are typed e.g. { name: string }
// 👆 context is typed e.g. { entitites: { Task: ... } }
const tasks = await context.entities.Task.findMany({});
return {
tasks,
};
};
When you use the job, you can pass the arguments and receive the result with the correct types:
import { simplePrintJob } from "@wasp/jobs/simplePrintJob.js";
...
const job = await simplePrintJob.submit({ name: "John" })
...
const result = await result.pgBoss.details()
// 👆 result is typed e.g. { tasks: Task[] }
1、 wasp-linux-x86_64.tar.gz 13.25MB
2、 wasp-macos-x86_64.tar.gz 6.01MB