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

Document public registration #22567

Merged
merged 9 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions docs/reference/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,201 @@ The query parameter option is not recommended in production setups as the parame

:::

## Register

Register a new user. Must first be enabled in project settings.

paescuj marked this conversation as resolved.
Show resolved Hide resolved
::: tip Register vs Create User

You can also use the [create user](/reference/system/users.html#create-a-user) endpoint, but this will require the
correct permissions on the `directus_users` collection. The register endpoint is publicly available if enabled in your
project.

:::

### Request

<SnippetToggler :choices="['REST', 'GraphQL', 'SDK']" group="api">
<template #rest>

`POST /register`

```json
{
"email": user_email,
"password": user_password
}
```

</template>
<template #graphql>

`POST /graphql/system`

```graphql
mutation {
users_register(email: "user_email", password: "user_password")
}
```

</template>
<template #sdk>

```js
import { createDirectus, rest, registerUser } from '@directus/sdk';

const client = createDirectus('directus_project_url').with(rest());

const result = await client.request(registerUser(email, password));
```

</template>
</SnippetToggler>

#### Request Body

`email` **Required**\
Email address of the user.

`password` **Required**\
Password of the user.

`first_name`\
First name of the user.

`last_name`\
Last name of the user.

`verification_url`\
Provide a custom verification URL which the link in the email will lead to. The verification token will be passed as a parameter.\
**Note**: You need to configure the
[`USER_REGISTER_URL_ALLOW_LIST` environment variable](/self-hosted/config-options#security) to enable this feature.
paescuj marked this conversation as resolved.
Show resolved Hide resolved

### Example

<SnippetToggler :choices="['REST', 'GraphQL', 'SDK']" group="api">
<template #rest>

`POST /register`

```json
{
"email": "user@example.com",
"password": "d1r3ctu5"
}
```

</template>
<template #graphql>

`POST /graphql/system`

```graphql
mutation {
users_register(email: "user@example.com", password: "d1r3ctu5")
}
```

</template>
<template #sdk>

```js
import { createDirectus, rest, registerUser } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(registerUser('user@example.com', 'd1r3ctu5'));
```

</template>
</SnippetToggler>

## Verify a Registration

If enabled in project settings, registering a user sends a verification email with a link to this endpoint (or a custom
URL) to allow the user to finish their registration.

### Request

<SnippetToggler :choices="['REST', 'GraphQL', 'SDK']" group="api">
<template #rest>

`POST /register/verify-email`

```json
{
"token": token
}
```

</template>
<template #graphql>

`POST /graphql/system`

```graphql
mutation {
users_register_verify(token: "token")
}
```

</template>
<template #sdk>

```js
import { createDirectus, rest, registerUserVerify } from '@directus/sdk';

const client = createDirectus('directus_project_url').with(rest());

const result = await client.request(registerUserVerify(token));
```

</template>
</SnippetToggler>

#### Request Body

`token` **Required**\
Verification token, as provided in the verification email sent by the registration endpoint.

### Example

<SnippetToggler :choices="['REST', 'GraphQL', 'SDK']" group="api">
<template #rest>

`POST /register/verify-email`

```json
{
"token": "eyJh...KmUk"
}
```

</template>
<template #graphql>

`POST /graphql/system`

```graphql
mutation {
users_register_verify(token: "eyJh...KmUk")
}
```

</template>
<template #sdk>

```js
import { createDirectus, rest, registerUserVerify } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(registerUserVerify('eyJh...KmUk'));
```

</template>
</SnippetToggler>

## Login

Authenticate as a user.
Expand Down
11 changes: 11 additions & 0 deletions docs/user-guide/user-management/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ Within the Data Studio, the [User Directory](/user-guide/user-management/user-di
users. However, certain controls are included in **Settings > Access Control > [Role]** as well, which is what the
following sections will focus on.

## Enable Public Registration

![Public registration settings showing a user registration checkbox, a verify email checkbox, the selection of a user role, and an email filter.](https://marketing.directus.app/assets/0d221e5b-a5f1-45f9-ba5a-71610b24724d.png)

To allow public registration directly from the login page of the Data Studio, follow these steps.
paescuj marked this conversation as resolved.
Show resolved Hide resolved

1. Navigate to **Settings > Settings**.
2. Enable User Registration.
3. Select a role for new users who register through this interface. Note: the admin role is not shown.
paescuj marked this conversation as resolved.
Show resolved Hide resolved
4. Optionally, enable email verification and create an email address filter.

## Invite a User

![How to invite a User](https://marketing.directus.app/assets/512793d0-be69-4ee6-9bc2-963e34f656a7.gif)
Expand Down
Loading