[英]load user.mail from Auth0 with async function
我想從 Auth0 加載 user.mail 並在常量中安全。 但我得到了一個箭頭。 我沒有看到錯誤。 有人可以幫我找到解決方案嗎?
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
看起來這些錯誤是由在服務器端運行的代碼引起的,它們無權訪問“文檔”等。 在 SvelteKit 中,端點始終在服務器上運行,因此無法訪問“客戶端 API”中的所有元素。
要防止代碼在服務器端運行,請嘗試通過OnMount()
調用它。 我已經鏈接了一個 Sapper 問題,概述了一些類似的解決方案,例如,使用if(process.browser)
。 我不確定這是否適用於 SvelteKit,但可能值得一試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.