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

sanitizeAndSerializeProviderData is missing await in seeding docs #2514

Open
infomiho opened this issue Feb 15, 2025 · 1 comment
Open

sanitizeAndSerializeProviderData is missing await in seeding docs #2514

infomiho opened this issue Feb 15, 2025 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@infomiho
Copy link
Contributor

Here: https://wasp.sh/docs/data-model/backends#writing-a-seed-function

Maybe it wouldn't be bad to rerun the seeding example code to verify it's up to date with latest Wasp version.

@infomiho infomiho added the documentation Improvements or additions to documentation label Feb 15, 2025
@seppulcro
Copy link

seppulcro commented Feb 15, 2025

Here's a more detailed example that I landed on while testing out wasp and going through the docks:

import { sanitizeAndSerializeProviderData } from "wasp/server/auth";
import { PrismaClient, Role, User } from "@prisma/client";

export const devSeedSimple = async (prisma: PrismaClient) => {
  await createUser(prisma, {
    username: "demo",
    password: "demo12345",
    role: Role.ADMIN,
  });
};

type CreateUserInput = {
  username: string;
  password: string;
} & Pick<User, "role">;

async function createUser(
  prisma: PrismaClient,
  data: CreateUserInput
): Promise<User> {
  const newUser = await prisma.user.create({
    data: {
      auth: {
        create: {
          identities: {
            create: {
              providerName: "username",
              providerUserId: data.username,
              providerData: await sanitizeAndSerializeProviderData({
                hashedPassword: data.password,
              }),
            },
          },
        },
      },
      role: data.role,
    },
  });

  return newUser;
}

This is working and intended and:

  • They can use types/enums from prisma schema
  • Shows users they can use type intersection if their model extends basic functionallity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants