[GH-ISSUE #1753] Better way to seed user/organization? #8900

Closed
opened 2026-04-13 04:08:59 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @j-fdion on GitHub (Mar 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1753

Is this suited for github?

  • Yes, this is suited for github

Currently there's no easy to seed users or orgs using better-auth api. I'm forced to use the backend apis to create my local server test accounts/orgs, but I find them not easy to use:

  const response = await auth.api.signUpEmail({
    asResponse: true,
    body: {
      email,
      name,
      password,
    },
    headers: new Headers({}),
  });

  const body = await response.text();
  const data: { user: { id: string } } = JSON.parse(body);
  const headers = new Headers();
  const header = response.headers.get('set-cookie');
  const cookies = parseSetCookieHeader(header || '');
  const signedCookie = cookies.get('better-auth.session_token')?.value;
  headers.set('cookie', `better-auth.session_token=${signedCookie}`);

  const userId = data.user.id;
  const user = await updateUser(userId, 'fr', role);

  const orgId = await auth.api
    .createOrganization({
      headers,
      body: {
        name: `${name}-org`,
        slug: `${name}-org`,
        userId: user.id,
      },
    })
    .then((i) => i?.id);

Describe the solution you'd like

I'd like a way to fill in users/orgs without messing with cookies/header like I'm doing right now.

Describe alternatives you've considered

None

Additional context

No response

Originally created by @j-fdion on GitHub (Mar 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1753 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently there's no easy to seed users or orgs using better-auth api. I'm forced to use the backend apis to create my local server test accounts/orgs, but I find them not easy to use: ``` const response = await auth.api.signUpEmail({ asResponse: true, body: { email, name, password, }, headers: new Headers({}), }); const body = await response.text(); const data: { user: { id: string } } = JSON.parse(body); const headers = new Headers(); const header = response.headers.get('set-cookie'); const cookies = parseSetCookieHeader(header || ''); const signedCookie = cookies.get('better-auth.session_token')?.value; headers.set('cookie', `better-auth.session_token=${signedCookie}`); const userId = data.user.id; const user = await updateUser(userId, 'fr', role); const orgId = await auth.api .createOrganization({ headers, body: { name: `${name}-org`, slug: `${name}-org`, userId: user.id, }, }) .then((i) => i?.id); ``` ### Describe the solution you'd like I'd like a way to fill in users/orgs without messing with cookies/header like I'm doing right now. ### Describe alternatives you've considered None ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:08:59 -05:00
Author
Owner

@jslno commented on GitHub (Mar 10, 2025):

Just do it in your orm directly.

<!-- gh-comment-id:2710969731 --> @jslno commented on GitHub (Mar 10, 2025): Just do it in your orm directly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8900