Skip to content

Commit

Permalink
Fix TypeScript example to use actually supported types (#756)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Dominguez <[email protected]>
  • Loading branch information
daniel-chambers and robertjdominguez authored Oct 31, 2024
1 parent 93a1bec commit 729a427
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/business-logic/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,28 @@ You can do this by adding the following code to the `functions.ts` file:
import { Client } from "pg";
import bcrypt from "bcrypt";

// Define the User type using TypeScript
type User = {
// Define a type to capture a new user's details using TypeScript
type NewUser = {
name: string;
email: string;
password: string; // Add a password field to the User type
};

// Define a type to capture the created User
type User = {
id: number;
name: string;
email: string;
};

/**
* Inserts a user into the database and returns the inserted user.
* Hash password for secure storage.
*
* @param user The user to insert into the database. Expects a name, email, and password.
* @returns The user that was inserted into the database.
*/
export async function insertUser(user: User): Promise<Omit<User, "password">> {
export async function insertUser(user: NewUser): Promise<User> {
// Get your database connection string.
// NB!! Use env vars for this in production NB!!
const connectionString = "postgresql://username:password@localhost:5432/mydb";
Expand Down

0 comments on commit 729a427

Please sign in to comment.