我正在尝试实现登录机械化,并且无法从回调函数返回值。我正在使用以下npm软件包:auth0-js。我的设置中有两个文件。 第一个是authService.js,其中有我的登录逻辑:
import auth0 from "auth0-js";
function initializeAuth0Client(domain, redirectUri, clientID) {
return new auth0.WebAuth({
domain: "{YOUR_AUTH0_DOMAIN}",
clientID: "{YOUR_AUTH0_CLIENT_ID}",
});
}
function handleLogin(client, user) {
return client.login(
{
realm,
username,
password,
},
(err, authResult) => {
if (authResult) {
return authResult;
}
}
);
}
module.exports = {
handleLogin,
initializeAuth0Client,
};
第二个:index.js
import { handleLogin, initializeAuth0Client } from "authService";
const auth0Client = initializeAuth0Client(domain, redirectUri, clientID);
const authResponse = handleLogin(auth0Client, user);
console.log(authResponse) // undefined
我尝试从回调中返回值,并将结果分配给函数内的局部变量并返回该值,但这些方法均未真正返回响应。我看到了this answer,但并没有太大帮助。