Create Organization Component - PropelAuth Docs

Create Organization Component

PropelAuth's Create Organization component allows you to customize the flow around a user creating an organization in your app.

Create Organization

Organization Name

Shadcn Installation

Install this component from our shadcn registry.

npx shadcn@latest add https://components.propelauth.com/r/create-organization.json

Reference APIs

These are the APIs that are used by the above component. You can use these APIs directly in your own code.

createOrg

Creates a new org and automatically adds the logged in user to it.

Arguments

Success Response

Response Functions

The response object has a handle function that you can use to handle the response. These functions can be async, and you can return values from them.

Request

const { createOrg } = useAuthFrontendApis()

const response = await createOrg({
    name: 'Acme Inc',
    allow_users_to_join_by_domain: true,
    restrict_invites_by_domain: true,
})
response.handle({
    success(data) {
        console.log(data)
    },
    cannotCreateOrgs(error) {
        console.log('Cannot create orgs', error.user_facing_error)
    },
    cannotUsePersonalDomain(error) {
        console.log('Cannot use personal domain', error.user_facing_error)
    },
    badRequest(error) {
        for (const [field, fieldErrorMessage] of Object.entries(error.user_facing_errors)) {
            console.log('Error: "' + fieldErrorMessage + '" for field: "' + field + '"')
        }
    },
    userAlreadyInTooManyOrgs(error) {
        console.log('User already in too many orgs', error.user_facing_error)
    },
    unexpectedOrUnhandled(error) {
        console.log('Unexpected or unhandled error', error.user_facing_error)
    },
})

Successful Response

{
    "org_id": "1189c444-8a2d-4c41-8b4b-ae43ce79a492",
    "first_org": true
}