Importing Ghost Blog Users to Appwrite

In Appwrite 1.0, a new feature has been added to migrate users from other platforms like Firebase, WordPress, Ghost, Supabase etc to Appwrite. So in this tutorial we are going to migrate all the users(members) from Ghost Blog to Appwrite and this is go…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Joysankar Majumdar

In Appwrite 1.0, a new feature has been added to migrate users from other platforms like Firebase, WordPress, Ghost, Supabase etc to Appwrite. So in this tutorial we are going to migrate all the users(members) from Ghost Blog to Appwrite and this is going to be super easy!

Let's do it 🦾

Step 1: Export users(members) from Ghost Blog

Firstly login to your Ghost admin and go to Settings page and then scroll down and go to Labs section.

Image description

Now in Labs, export your content in a json file by clicking the Export button.

Image description

You'll get a json file of all your contents like this

Image description
This json file contains all the users' data. Now we need to import all the data into the Appwrite.

Step 2: Import Users to Appwrite

To import users into Appwrite, we can use any Server SDK to access the Users API. For this example, we will use the NodeJS SDK.

Newly added functions let you create a user with one of 7 different hashing algorithms. Ghost uses Bcrypt algorithm for saving passwords. So we will use Bcrypt Password in Appwrite Server SDK to import users.

async createBcryptUser(
        userId,
        email,
        password,
        name
      );

Going through the function parameters one by one:

  • userId: The ID to assign to the new user in Appwrite. It can be custom, or you can use the SDK's new ID.unique() function to assign a randomly generated ID.
  • email: Corresponds to the email value from the json file.
  • password: Corresponds to the passwordHash value from json file.
  • name: The name to assign to the user. Can be null.

Putting this all together, we could import all of the exported users into Appwrite like so:

const outfile = "cozblog.ghost.2022-10-24-17-31-47.json";
  const json = await fs.readFile(outfile, { encoding: "utf8" });
  const exported = JSON.parse(json).db[0].data.users;
  await Promise.all(
    exported.map(async (user) => {
      await users.createBcryptUser(
        ID.unique(),
        user.email,
        user.password,
        user.name
      );
    })
  );

After all the user export the Appwrite dashboard looks like this

Image description

So now the whole code looks like this


const sdk = require("node-appwrite");
const { ID } = require("node-appwrite");
const fs = require('fs/promises');

let client = new sdk.Client();

const users = new sdk.Users(client);

const endPoint = "Your End Point";
const projectId = "Your Project Id";
const apiKey = "Your Api Key";
client
  .setEndpoint(endPoint)
  .setProject(projectId)
  .setKey(apiKey)
  .setSelfSigned();

const migrate = async () => {
  const outfile = "cozblog.ghost.2022-10-24-17-31-47.json";
  const json = await fs.readFile(outfile, { encoding: "utf8" });
  const exported = JSON.parse(json).db[0].data.users;
  await Promise.all(
    exported.map(async (user) => {
      await users.createBcryptUser(
        ID.unique(),
        user.email,
        user.password,
        user.name
      );
    })
  );
};

migrate()
  .then((r) => console.log("Done!"))
  .catch((e) => console.log(e));

Hope you learn how to migrate users from WordPress to Appwrite.
Don't forget to follow me @joysankar2001


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Joysankar Majumdar


Print Share Comment Cite Upload Translate Updates
APA

Joysankar Majumdar | Sciencx (2022-10-25T09:31:57+00:00) Importing Ghost Blog Users to Appwrite. Retrieved from https://www.scien.cx/2022/10/25/importing-ghost-blog-users-to-appwrite/

MLA
" » Importing Ghost Blog Users to Appwrite." Joysankar Majumdar | Sciencx - Tuesday October 25, 2022, https://www.scien.cx/2022/10/25/importing-ghost-blog-users-to-appwrite/
HARVARD
Joysankar Majumdar | Sciencx Tuesday October 25, 2022 » Importing Ghost Blog Users to Appwrite., viewed ,<https://www.scien.cx/2022/10/25/importing-ghost-blog-users-to-appwrite/>
VANCOUVER
Joysankar Majumdar | Sciencx - » Importing Ghost Blog Users to Appwrite. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/25/importing-ghost-blog-users-to-appwrite/
CHICAGO
" » Importing Ghost Blog Users to Appwrite." Joysankar Majumdar | Sciencx - Accessed . https://www.scien.cx/2022/10/25/importing-ghost-blog-users-to-appwrite/
IEEE
" » Importing Ghost Blog Users to Appwrite." Joysankar Majumdar | Sciencx [Online]. Available: https://www.scien.cx/2022/10/25/importing-ghost-blog-users-to-appwrite/. [Accessed: ]
rf:citation
» Importing Ghost Blog Users to Appwrite | Joysankar Majumdar | Sciencx | https://www.scien.cx/2022/10/25/importing-ghost-blog-users-to-appwrite/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.