Create a new Embed
Login to your account on Mirin and create a new Embed. You will then need to generate a new Private Key that you will use to setup the SDKs later in this guide.Project setup
- Install Next.js
- Install SDK
cd
into the project directory and install the following packages:
- Add your private key
.env.local
file and add your Embed’s private key.
- Setup the Admin client
Client
which we’ll use to perform priviledged operations such as authenticating our users into our new embedded Mirin editor.
Typically, this will live in your backend and you would create API endpoints to interface with the Client
. In Next.js 15, we can use server actions without having to create a separate backend:
lib/server.tsx
Creating Documents
Before we can actually launch the editor, we need to first have some Documents that we can edit. Let’s now create a simple Dashboard page where we can:-- List all Documents associated with our Embed
- Let our user to create a new Document
lib/server.tsx
Setup the editor
Onto the most exciting part - actually integrating the editor. The editor requires a valid session token in order to authenticate the user and to fetch the correct user document to display in the editor. We can generate this token with our adminClient
- so let’s create a new server action to do just that:
lib/server.tsx
documentId
argument which our page on the frontend will pass, and we’re generating a valid token that effectively grants the user access to the edit the document on our Editor.
In a real app, you probably want to add additional logic here - e.g. to check if your user has the correct permissions to edit a given document.
TheFinally, let’s create a new page in our project where we’ll render our editor.client.authorize()
method accepts a context object, by default - this object is used to specify thedocumentId
to grant the user access to edit.
app/editor/[documentId]/page.tsx