从回调函数返回值

问题描述

我正在尝试实现登录机械化,并且无法从回调函数返回值。我正在使用以下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,clientID);
const authResponse = handleLogin(auth0Client,user);
console.log(authResponse) // undefined

我尝试从回调中返回值,并将结果分配给函数内的局部变量并返回该值,但这些方法均未真正返回响应。我看到了this answer,但并没有太大帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)