magic-admin-js icon indicating copy to clipboard operation
magic-admin-js copied to clipboard

I want to use the getMetadataByToken method in Next JS 13 in api routes with an error Magic Admin SDK Error: [SERVICE_ERROR]

Open hamedtarkashvand opened this issue 2 years ago • 0 comments

✅ Prerequisites

  • [ ] Did you perform a cursory search of open issues? Is this question already asked elsewhere?
  • [ ] Are you reporting to the correct repository (@magic-sdk/admin)?

❓ Question

I want to use the getMetadataByToken method in Next JS 13 in api routes with an error Magic Admin SDK Error: [SERVICE_ERROR] A service error occurred while communicating with the Magic API. I observe

// config magic-admin.js

import { Magic } from "@magic-sdk/admin";
export const magicAdmin = new Magic(process.env.MAGIC_SECRET_KEY);
// pages/api/login.js

import { magicAdmin } from "@/lib/magic-admin";

export default async function login(req, res) {
  const auth = req.headers.authorization;
 const didToken = magicAdmin.utils.parseAuthorizationHeader(auth);
  if (req.method === 'POST') {
    try {
      const metaData = await magicAdmin.users.getMetadataByToken(didToken);
      console.log(metaData);
      res.send({ done: true });
    } catch (err) {
      console.error('something want error ===>', err);
      res.status(500).json({ done: false });
    }
  } else {
    res.send({ done: false });
  }

🌎 Environment

Software Version(s)
@magic-sdk/admin ^1.10.0
Node v18.15.0
Operating System windows 10

hamedtarkashvand avatar Jun 08 '23 21:06 hamedtarkashvand