【问题标题】:load user.mail from Auth0 with async function使用异步功能从 Auth0 加载 user.mail
【发布时间】:2021-11-28 17:40:01
【问题描述】:

我想从 Auth0 加载 user.mail 并在 const 处安全。但我得到一个箭头。我没有看到错误。有人可以帮我找到解决方案吗?

const userMailInfo = async () => {


 auth0Client = await auth.createClient();

  const result = await auth0Client.getUser().then(user => {
    console.log('mail', user.email);
    user.mail;
  });
  return result;
}

;(async () => {
  const users = await userMailInfo()
  console.log(users)
})()

我收到跟随错误:

(node:19676) UnhandledPromiseRejectionWarning: ReferenceError: document is not defined

【问题讨论】:

  • then 回调没有返回。对于此处显示的错误,代码也不完整。我认为错误发生在其他地方。

标签: javascript node.js auth0 sveltekit


【解决方案1】:

看起来这些错误是由在服务器端运行的代码引起的,它们无权访问“文档”等。在 SvelteKit 中,端点始终在服务器上运行,因此无法访问“客户端 API”中的所有元素。

要防止代码在服务器端运行,请尝试通过OnMount() 调用它。我已经链接了一个 Sapper 问题,概述了一些类似的解决方案,例如,使用 if(process.browser)。我不确定这是否适用于 SvelteKit,但可能值得一试。

注意:似乎错误发生在提供的代码 sn-p 之外。


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-10
    • 2017-02-25
    • 2019-01-02
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    • 2011-06-25
    相关资源
    最近更新 更多