Skip to main content

Deleted the stored data

You can either delete all the user's metadata, or ceetain fields from them:

Deleting specific fields from the metadata object#

This can be done by calling the update metadata function and setting the field you want to remove to be null. For example, if you have the following metadata object for a user:

{
"preferences": { "theme": "dark" },
"notifications": { "email": true },
"todos": ["use-text-notifs"]
}

And you want to remove the "notifications" field, you can update the metadata object with the following JSON:

{
"notifications": null
}

This would result in the final metadata object:

{
"preferences": { "theme": "dark" },
"todos": ["use-text-notifs"]
}
important

You can only remove the root level fields in the metadata object in this way. From the above example, if you set preferences.theme: null, then it will not remove the "theme" field, but instead set it to a JSON null value.

In code, it would look like:

import express from "express";
import { verifySession } from "supertokens-node/recipe/session/framework/express";
import UserMetadata from "supertokens-node/recipe/usermetadata";

let app = express();

app.post("/updateinfo", verifySession(), async (req, res) => {
const session = req.session;
const userId = session.getUserId();

await UserMetadata.updateUserMetadata(userId, { notifications: null });

res.json({ message: "successfully updated user metadata" });
});

Deleting the entire metadata object#

Using this function will delete all the fields in the user metadata object for that user.

import express from "express";
import { verifySession } from "supertokens-node/recipe/session/framework/express";
import UserMetadata from "supertokens-node/recipe/usermetadata";

let app = express();

app.post("/updateinfo", verifySession(), async (req, res) => {
const session = req.session;
const userId = session!.getUserId();

await UserMetadata.clearUserMetadata(userId);

res.json({ success: true });
});
Looking for older version of the documentation?
Which UI do you use?
Custom UI
Pre built UI