Skip to content

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

@hamedtarkashvand

Description

@hamedtarkashvand

✅ 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions