【问题标题】:What is causing this "Illegal base64 data" error?是什么导致了这个“非法 base64 数据”错误?
【发布时间】:2021-12-20 06:22:45
【问题描述】:

我一直在使用 Next 和 GraphQL 开展一个项目,但我很难弄清楚是什么导致了以下错误:

ClientError: GraphQL Error (Code: 400): {"response":{"error":"{\"errors\":[{\"message\":\"parse token failed: illegal base64 data at input byte 0\"}],\"data\":null}","status":400,"headers":{}},"request":{"query":"mutation CreateComment($name: String!, $email: String!, $comment: String!, $slug: String!) {createComment(data: {name: $name, email: $email, comment: $comment, post: { connect: { slug: $slug } } }) { id }}","variables":{"name":"Nate","email":"dasdasd@asasd","comment":"test","slug":"test-slug"}}}

这是我的问题。我已经尝试删除任何多余的空格和我发现的任何拼写错误。令牌拉得很好,除了错误之外,其他一切似乎都很好:

  console.log(graphcmsToken)
  const { name, email, slug, comment } = req.body;
  const graphQLClient = new  GraphQLClient(graphqlAPI, {
    headers: {
      authorization: `Bearer ${graphcmsToken}`}
  })

  const query = gql`mutation CreateComment($name: String!, $email: String!, $comment: String!, $slug: String!) {createComment(data: {name: $name, email: $email, comment: $comment, post: { connect: { slug: $slug } } }) { id }}`
try {
  const result = await graphQLClient.request(query, req.body)

  return res.status(200).send(result);
} catch (error){
  console.log(error)
  return res.status(500).send(error)
}

提前致谢!这一直困扰着我的时间比我想承认的要长,当我尝试在这里搜索答案时,我对 JS/Next/GraphQL 的运气特别差。

【问题讨论】:

  • 那么base64数据是什么样的?
  • 你实际上回答了我的问题——我看错了地方。我的令牌有破损,我没有修复 - 谢谢!

标签: javascript graphql request next.js


【解决方案1】:

问题出在令牌中——复制和粘贴它添加了一些导致问题的额外格式。

【讨论】:

    猜你喜欢
    • 2015-12-24
    • 2011-08-13
    • 2012-10-06
    • 2012-09-21
    • 2010-10-12
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多