0

Hi guys this is my user registration api code

That trying to mutate sanity user document field

It's taking user's name, email, password

All imports

import { createRouter } from "next-connect";
import bcrypt from "bcryptjs";
import axios from "axios";
import { signToken } from "../../../../lib/auth";

post request

handler.post(async (req, res) => {
const projectId = "SOMETHING";
const dataset = SOMETHING
const apiVersion = "SOMETHING";
const tokenWithWriteAccess = process.env.NEXT_PUBLIC_SANITY_TOKEN;
const createMutations = [
{
create: {
_type: "user",
name: req.body.name,
email: req.body.email,
password: bcrypt.hashSync(req.body.password),
isAdmin: false,
},
},
];

post request to sanity with mutations payload

const { data } = await axios.post(
https://${projectId}.api.sanity.io/v${apiVersion}/data/mutate/${dataset}?returnIds=true,
{ mutations: createMutations },
{
headers: {
"Content-type": "application/json",
Authorization: Bearer ${tokenWithWriteAccess},
},
}
);
const userId = data.results[0].id;
const user = {
_id: userId,
name: req.body.name,
email: req.body.email,
isAdmin: false,
};

passing the response to client

const token = signToken(user);
res.send({ ...user, token });
});

export default handler;

And i am getting this error and call stack

k3ydow
  • 1
  • 2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 13 '23 at 17:42

0 Answers0