Cannot create organizations
Hello,
I am trying to generate mock data with authClient.organization.create() but it doesn't work.
Has someone any idea ?
I am using SvelteKit



33 Replies
don't use the
authClient
use auth
instance and call auth.api.createOrganization
i am getting this error


Try adding headers in the createOrganization as well
ok but what do i need to make into it ?
What are you using? Nextjs or something else?
SvelteKit
Let me check the docs
Thank you
SvelteKit Integration | Better Auth
Integrate Better Auth with SvelteKit.
This is how they are adding headers in svelte
i am into a seed.ts file
i want to make data
its not running through this file
Oh you are in a seeding file, I've never tried seeding data with better-auth yet. But you cant get headers in a seeding file since there are no headers, and if there are no headers there is no session.
createOrganization
needs to know who the owner is, you can pass userId
in the body but I have no idea if it will return an unauthorized response or notok so i need to make it work doing the normal flow
thank you
I have another question
you must make a dashboard to make it possible to create organisation ?
I dont know what you mean, but you need a user in order to create an organization. Organization has 2 tables,
Organization
table and Member
table. Member table links to the organization and the user and the role of the user in the organization
When you create an organization with a user logged in, the user will be added as the owner of the organizationOrganization | Better Auth
The organization plugin allows you to manage your organization's members and teams.
and is admin library worth to use along organisation library ?
I havent used the admin library yet, but the admin has roles in the user table, while the roles in Organization is in Members table, so they are completely seperate things
Organization already has 3 roles "Owner", "Admin", "Member", but you can add more if you want with their permissions
Organization | Better Auth
The organization plugin allows you to manage your organization's members and teams.
Thank you
Also for your seeding, you can create the seed manually instead of using better-auth
For example you can create an organization by adding an organization with all its fields to the database as well as adding the member part for it.
Example for what i used before, this is a function i use to create an organization when someone pays successfuly, i wont have their session but i would have their userId so i do the rest manually

interesting. So you only need userId to make a new organisation ?
Yes, you can create a user and take his id and use it for creating the organization as well, all asynchronously so that you get the id of each one. But one more note, you need to create the ID as you can see above
1. Create userId, then create user with the generated userId
2. Create organizationId, then create an organization with generated organizationId and userId before
3. Create the Member connection with the userId and organizationId and the role you want "owner", "admin", or "member"
I think this is the fastest way for a seed file
Thank you a lot
@Kazz It works thx. I have another question. sessions and members tables are empties. They are used while logging in ?
Session table is for the login session
Member table is for users in organization, so if user1 created or joined an organization, they will be added to the member table with their role in the organization (userId, orgId, role)
Ah yes, my members table is filled
Thank you
@Kazz I would like to log in with an account so I need to add data into account table ?
in my drizzle studio, i have no record into this table
Accounts are different providers you are logging in with that links to the user. So if a user logs in with google and github with the same email, they will both be linked to the same user. You just beed providers
I will use Email/password first
i would like to find a way to hash my password but what to use to hash a password
Bcrypt
in the doc, it says scrypt
You can use whatever you want
My thought is: I want to create a account manually, then tried to log in with my frontend app. So i need to sync hash and comparehash algorithme so it can work
I will need to change the hash and verify
Email & Password | Better Auth
Implementing email and password authentication with Better Auth.