Skip to content

Commit

Permalink
v5 updates (#619)
Browse files Browse the repository at this point in the history
Co-authored-by: Lennart <[email protected]>
  • Loading branch information
alexisintech and LekoArts committed Mar 5, 2024
1 parent acd9341 commit 4f6929b
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 56 deletions.
8 changes: 4 additions & 4 deletions docs/backend-requests/handling/nodejs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Clerk Node SDK offers two authentication middlewares specifically for [Expre

<CodeBlockTabs type="js-ts" options={["JavaScript", "TypeScript"]}>
```js
import "dotenv/config"; // To read CLERK_API_KEY
import "dotenv/config"; // To read CLERK_SECRET_KEY
import { ClerkExpressWithAuth } from "@clerk/clerk-sdk-node";
import express from "express";

Expand All @@ -41,7 +41,7 @@ app.listen(port, () => {
```

```typescript
import "dotenv/config"; // To read CLERK_API_KEY
import "dotenv/config"; // To read CLERK_SECRET_KEY
import {
ClerkExpressWithAuth,
LooseAuthProp,
Expand Down Expand Up @@ -87,7 +87,7 @@ app.listen(port, () => {

<CodeBlockTabs type="js-ts" options={["JavaScript", "TypeScript"]}>
```js
import "dotenv/config"; // To read CLERK_API_KEY
import "dotenv/config"; // To read CLERK_SECRET_KEY
import { ClerkExpressRequireAuth } from '@clerk/clerk-sdk-node';
import express from 'express';

Expand Down Expand Up @@ -118,7 +118,7 @@ app.listen(port, () => {
```

```typescript
import "dotenv/config"; // To read CLERK_API_KEY
import "dotenv/config"; // To read CLERK_SECRET_KEY
import {
ClerkExpressRequireAuth,
RequireAuthProp,
Expand Down
14 changes: 5 additions & 9 deletions docs/components/clerk-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ The `<ClerkProvider>` component must be added to your React entrypoint.
<Tab>
The `<ClerkProvider>` component needs to access headers to authenticate correctly. This means anything wrapped by the provider will be opted into dynamic rendering at request time. If you have static-optimized or ISR pages that you would prefer not to be opted into dynamic rendering, make sure they are not wrapped by `<ClerkProvider>`.

This is easiest to accomplish by ensuring that `<ClerkProvider>` is added further down the tree to wrap route groups that explicitly need authentication instead of having the provider wrap your application root as recommended above. For example, if your project includes a set of landing/marketing pages as well as a dashboard that requires login, you would create separate (marketing) and (dashboard) route groups. Adding `<ClerkProvider>` to the (dashboard)/layout.jsx layout file will ensure that only those routes are opted into dynamic rendering, allowing the marketing routes to be statically optimized.

<Callout type="info">
The root layout is a server component. If you plan to use the `<ClerkProvider>` outside the root layout, it will need to be a server component as well.
</Callout>
This is easiest to accomplish by ensuring that `<ClerkProvider>` is added further down the tree to wrap route groups that explicitly need authentication instead of having the provider wrap your application root as recommended above. For example, if your project includes a set of landing/marketing pages as well as a dashboard that requires login, you would create separate (marketing) and (dashboard) route groups. Adding `<ClerkProvider>` to the `(dashboard)/layout.jsx` layout file will ensure that only those routes are opted into dynamic rendering, allowing the marketing routes to be statically optimized.

<CodeBlockTabs type="router" options={["App Router", "Pages Router"]}>

Expand Down Expand Up @@ -52,7 +48,7 @@ The `<ClerkProvider>` component must be added to your React entrypoint.
function MyApp({ Component, pageProps }: AppProps) {
return (
<ClerkProvider {...pageProps}>
<Component {...pageProps} />
<Component {...pageProps} />
</ClerkProvider>
);
}
Expand Down Expand Up @@ -93,9 +89,9 @@ The `<ClerkProvider>` component must be added to your React entrypoint.

| Name | Type | Description |
| ------------------------- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `publishableKey` | `string` | Clerk publishable key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page. |
| `frontendApi` | `string` | The frontend API host for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page under the **Advanced** section. |
| `navigate?` | `(to: string) => Promise<unknown> \| void` | A function which takes the destination path as an argument and performs a "push" navigation. |
| `publishableKey` | `string` | The Clerk publishable key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page. |
| `routerPush?` | `(to: string) => Promise<unknown> \| void` | A function which takes the destination path as an argument and performs a "push" navigation. |
| `routerReplace?` | `(to: string) => Promise<unknown> \| void` | A function which takes the destination path as an argument and performs a "replace" navigation. |
| `clerkJSUrl?` | `string` | Define the URL that `@clerk/clerk-react` should hot-load `@clerk/clerk-js` from. |
| `clerkJSVariant?` | `string` | If your web application only uses Control components, you can set this value to `headless` and load a minimal ClerkJS bundle for optimal page performance. |
| `clerkJSVersion?` | `string` | Define the npm version for `@clerk/clerk-js`. |
Expand Down
4 changes: 2 additions & 2 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@
"/references/backend/organization/get-organization-membership-list"
],
[
"getPendingOrganizationInvitationList()",
"/references/backend/organization/get-pending-organization-invitation-list"
"getOrganizationInvitationList()",
"/references/backend/organization/get-organization-invitation-list"
],
[
"createOrganization()",
Expand Down
2 changes: 1 addition & 1 deletion docs/organizations/updating-organizations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default function EditOrganization({ organizationId }) {
async function init() {
// This is the current organization ID.
const organizationId = "org_XXXXXXX";
const organizationMemberships = await window.Clerk.getOrganizationMemberships()
const organizationMemberships = await window.Clerk.user.getOrganizationMemberships()
const currentMembership = organizationMemberships.find(membership
=> membership.organization.id === organizationId);
const currentOrganization = currentMembership.organization;
Expand Down
6 changes: 3 additions & 3 deletions docs/organizations/viewing-memberships.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Learn how to view organization memberships for the currently signed

Clerk provides the ability for the currently signed-in user to view all the organizations they are members of.

In React and Next.js applications, the [`useOrganizationList()`](/docs/references/react/use-organization-list) hook can be used to return the list of invitations or memberships for the currently active user. In JavaScript applications, the [`getOrganizationMemberships()`](/docs/references/javascript/clerk/organization-methods#get-organization-memberships) method is used to retrieve the list of organizations the current user is a part of and can be accessed through the [`Clerk` object](/docs/references/javascript/clerk/clerk).
In React and Next.js applications, the [`useOrganizationList()`](/docs/references/react/use-organization-list) hook can be used to return the list of invitations or memberships for the currently active user. In JavaScript applications, the [`getOrganizationMemberships()`](/docs/references/javascript/user/user#get-organization-memberships) method is used to retrieve the list of organizations the current user is a part of and can be accessed through the [`User` object](/docs/references/javascript/user/user).

{/* TODO (DOCS-316): Add a section about viewing all memberships for an organization.
Expand All @@ -17,7 +17,7 @@ You can use the `getOrganizationMembershipList()` method to retrieve a list of m

## Usage

{/* TODO (DOCS-316): Update and validate these code examples. */}
{/* TODO (DOCS-316): Update and validate these code examples. Should have Nextjs App Router and JavaScript only. */}

<CodeBlockTabs type="framework" options={["Next.js", "React", "JavaScript"]}>
```tsx filename="pages/joined-organizations.tsx"
Expand Down Expand Up @@ -112,7 +112,7 @@ export default JoinedOrganizationList;
<script>
const list = document.getElementById("organizations_list");
try {
const organizationMemberships = await window.Clerk.getOrganizationMemberships();
const organizationMemberships = await window.Clerk.user.getOrganizationMemberships();

organizationMemberships.map((membership) => {
const li = document.createElement("li");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
---
title: getPendingOrganizationInvitationList()
title: getOrganizationInvitationList()
description: Retrieves a list of organization invitations that have not yet been accepted.
---

# `getPendingOrganizationInvitationList()`
# `getOrganizationInvitationList()`

Retrieves a list of organization invitations that have not yet been accepted.

```tsx
const organizationId = 'my-organization-id';

const invitations = await clerkClient.organizations.getPendingOrganizationInvitationList({ organizationId });
const invitations = await clerkClient.organizations.getOrganizationInvitationList({ organizationId });
```

## `GetPendingOrganizationInvitationListParams`
## `GetOrganizationInvitationListParams`

| Name | Type | Description |
| --- | --- | --- |
| `organizationId` | `string` | The ID of the organization to retrieve the list of pending invitations from. |
| `status?` | [ 'pending' | 'accepted' | 'status' ] | Filters the list of invitations by status. |
| `limit?` | `number` | The number of results to return. Must be an integer greater than zero and less than 500. |
| `offset?` | `number` | The number of results to skip. |

## Examples

### `getPendingOrganizationInvitationList({ limit })`
### `getOrganizationInvitationList({ status })`

Retrieves organization invitation list that is filtered by the status of the invitation.

```tsx
const organizationId = 'my-organization-id';

const invitations = await clerkClient.organizations.getOrganizationInvitationList({
organizationId,
// returns a list of invitations that have not yet been accepted
status: [ 'pending' ],
});
```

### `getOrganizationInvitationList({ limit })`

Retrieves organization invitation list that is filtered by the number of results.

```tsx
const organizationId = 'my-organization-id';

const invitations = await clerkClient.organizations.getPendingOrganizationInvitationList({
const invitations = await clerkClient.organizations.getOrganizationInvitationList({
organizationId,
// returns the first 10 results
limit: 10,
});
```

### `getPendingOrganizationInvitationList({ offset })`
### `getOrganizationInvitationList({ offset })`

Retrieves organization invitation list that is filtered by the number of results to skip.

```tsx
const organizationId = 'my-organization-id';

const invitations = await clerkClient.organizations.getPendingOrganizationInvitationList({
const invitations = await clerkClient.organizations.getOrganizationInvitationList({
organizationId,
// skips the first 10 results
offset: 10,
Expand Down
2 changes: 1 addition & 1 deletion docs/references/backend/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Organization operations are exposed under `clerkClient.organizations`. The follo
- [`getOrganization()`](/docs/references/backend/organization/get-organization)
- [`getOrganizationList()`](/docs/references/backend/organization/get-organization-list)
- [`getOrganizationMembershipList()`](/docs/references/backend/organization/get-organization-membership-list)
- [`getPendingOrganizationInvitationList()`](/docs/references/backend/organization/get-pending-organization-invitation-list)
- [`getOrganizationInvitationList()`](/docs/references/backend/organization/get-organization-invitation-list)

### Organization `create` operations

Expand Down
14 changes: 0 additions & 14 deletions docs/references/javascript/clerk/organization-methods.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,5 @@ function createOrganization(params: CreateOrganizationParams): Promise<Organizat
```
</CodeBlockTabs>

## `getOrganizationMemberships()`

Get a list of all organizations your current user is a part of in the form of an array of [`OrganizationMembership`][orgmem-ref]s.

```typescript
function getOrganizationMemberships(): Promise<OrganizationMembership[]>;
```

### `getOrganizationMemberships()` returns

| Type | Description |
| --- | --- |
| <code>Promise\<[OrganizationMembership][orgmem-ref][]\></code> | This method returns a `Promise` which resolves to the list of [`OrganizationMembership`][orgmem-ref]s for the current user. |

[org-ref]: /docs/references/javascript/organization/organization
[orgmem-ref]: /docs/references/javascript/organization-membership
2 changes: 1 addition & 1 deletion docs/references/javascript/organization/domains.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ function createDomain: (domainName: string) => Promise<OrganizationDomainResourc


[org-domain-ref]: /docs/references/javascript/organization-domain
[pag-res-ref]: /docs/references/javascript/types/paginated-response
[pag-res-ref]: /docs/references/javascript/types/clerk-paginated-response
[enrollment-mode-ref]: /docs/organizations/verified-domains#enrollment-modes
2 changes: 1 addition & 1 deletion docs/references/javascript/organization/invitations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ function inviteMembers(params: InviteMembersParams): Promise<OrganizationInvitat
| <code>Promise\<[OrganizationInvitation][orginv-ref][]\></code> | This method returns a `Promise` which resolves to a list of [`OrganizationInvitation`][orginv-ref]s for the created invitations. |

[orginv-ref]: /docs/references/javascript/organization-invitation
[pag-res-ref]: /docs/references/javascript/types/paginated-response
[pag-res-ref]: /docs/references/javascript/types/clerk-paginated-response
2 changes: 1 addition & 1 deletion docs/references/javascript/organization/members.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ function removeMember(userId: string): Promise<OrganizationMembership>;
| --- | --- |
| <code>Promise\<[OrganizationMembership][org-mem-ref]\></code> | This method returns a `Promise` which resolves with the removed [`OrganizationMembership`][org-mem-ref] object. |

[pag-ref]: /docs/references/javascript/types/paginated-response
[pag-ref]: /docs/references/javascript/types/clerk-paginated-response
[org-mem-ref]: /docs/references/javascript/organization-membership
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ function getMembershipRequests(params?: GetMembershipRequestParams): Promise<Pag
| <code>Promise\<[PaginatedResponse][pag-res-ref]\<[OrganizationMembershipRequest][mem-request-ref]\>></code> | This method returns a `Promise` which resolves with a list of `OrganizationMembershipRequest` objects. |

[mem-request-ref]: /docs/references/javascript/organization-membership-request
[pag-res-ref]: /docs/references/javascript/types/paginated-response
[pag-res-ref]: /docs/references/javascript/types/clerk-paginated-response
3 changes: 1 addition & 2 deletions docs/references/javascript/organization/organization.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Organization
description: This is a class that represents an organziation. It's returned from the createOrganization and getOrganization methods on the Clerk class instance.
description: This is a class that represents an organization. It's returned from the createOrganization and getOrganization methods on the Clerk class instance.
---

# `Organization`
Expand All @@ -14,7 +14,6 @@ This is a class that represents an organization. It's returned from the [`create
| `id` | `string` | The unique identifier of the related organization. |
| `name` | `string` | The name of the related organization. |
| `slug` | `string \| null` | The organization slug. If supplied, it must be unique for the instance. |
| `logoUrl` (deprecated) | `string \| null` | Deprecated in favor of `imageUrl`. |
| `imageUrl` | `string` | Holds the organization logo or default logo. Compatible with Clerk's [Image Optimization](/docs/guides/image-optimization/imageurl-image-optimization). |
| `hasImage` | `boolean` | A getter boolean to check if the organization has an uploaded image. Returns `false` if Clerk is displaying an avatar for the organization. |
| `membersCount` | `number` | The number of members the associated organization contains. |
Expand Down
4 changes: 2 additions & 2 deletions docs/references/javascript/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ Add the following script to your site's `<body>` element:
// Creates asynchronous script
const script = document.createElement('script');
script.setAttribute('data-clerk-frontend-api', frontendApi);
script.setAttribute('data-clerk-frontend-api', frontendApiUrl);
script.setAttribute('data-clerk-publishable-key', clerkPublishableKey);
script.async = true;
script.src = `https://${frontendApi}/npm/@clerk/clerk-js${version}/dist/clerk.browser.js`;
script.src = `https://${frontendApiUrl}/npm/@clerk/clerk-js${version}/dist/clerk.browser.js`;
// Adds listener to initialize ClerkJS after it's loaded
script.addEventListener('load', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ An interface that describes the response of a method that returns a paginated li

## Error handling

Clerk's SDKs always use `Promise<ClerkPaginatedResponse<T>>`. If the promise resolves, you will get back the [properties](#properties) listed above. If the promise is rejected, you will receive a `ClerkAPIResponseError` or network error.
Clerk's SDKs always use `Promise<ClerkPaginatedResponse<T>>`. If the promise resolves, you will get back the [properties](#properties) listed above. If the promise is rejected, you will receive a `ClerkAPIResponseError` or network error.
Loading

0 comments on commit 4f6929b

Please sign in to comment.