index.js
function loginCallback(options) {
  return async function loginCallbackHandler(ctx) {
    let referer;
    // customize how to get redirect target
    if (options.getRedirectTarget) {
      referer = options.getRedirectTarget(ctx);
    }
    if (!referer) referer = ctx.session.userauthLoginReferer || options.rootPath;

    debug('loginReferer in session: %j', ctx.session.userauthLoginReferer);
    // cleanup the userauthLoginReferer on session
    ctx.session.userauthLoginReferer = undefined;
    let user = ctx.session[options.userField];
    if (user) {
      // already login
      return redirect(ctx, referer);
    }
    user = await options.getUser(ctx);
    if (!user) {
      return redirect(ctx, referer);
    }

    const res = await options.loginCallback(ctx, user);
    const loginUser = res[0];
    const redirectURL = res[1];
    ctx.session[options.userField] = loginUser;
    if (redirectURL) {
      referer = redirectURL;
    }
    redirect(ctx, referer);
  };
}
function loginCallback(options) {
  return async function loginCallbackHandler(ctx) {
    let referer;
    // customize how to get redirect target
    if (options.getRedirectTarget) {
      referer = options.getRedirectTarget(ctx);
    }
    if (!referer) referer = ctx.session.userauthLoginReferer || options.rootPath;

    debug('loginReferer in session: %j', ctx.session.userauthLoginReferer);
    // cleanup the userauthLoginReferer on session
    ctx.session.userauthLoginReferer = undefined;
    let user = ctx.session[options.userField];
    if (user) {
      // already login
      return redirect(ctx, referer);
    }
    user = await options.getUser(ctx);
    if (!user) {
      return redirect(ctx, referer);
    }

    const res = await options.loginCallback(ctx, user);
    const loginUser = res[0];
    const redirectURL = res[1];
    ctx.session[options.userField] = loginUser;
    if (redirectURL) {
      referer = redirectURL;
    }
    redirect(ctx, referer);
  };
}
function loginCallback ( options ) { return async function loginCallbackHandler ( ctx ) { let referer ; // customize how to get redirect target if ( options . getRedirectTarget ) { referer = options . getRedirectTarget ( ctx ) ; } if ( ! referer ) referer = ctx . session . userauthLoginReferer || options . rootPath ; debug ( 'loginReferer in session: %j' , ctx . session . userauthLoginReferer ) ; // cleanup the userauthLoginReferer on session ctx . session . userauthLoginReferer = undefined ; let user = ctx . session [ options . userField ] ; if ( user ) { // already login return redirect ( ctx , referer ) ; } user = await options . getUser ( ctx ) ; if ( ! user ) { return redirect ( ctx , referer ) ; } const res = await options . loginCallback ( ctx , user ) ; const loginUser = res [ 0 ] ; const redirectURL = res [ 1 ] ; ctx . session [ options . userField ] = loginUser ; if ( redirectURL ) { referer = redirectURL ; } redirect ( ctx , referer ) ; } ; }
return a loginCallbackHandler
@param {Object} options
@return {Function}
return a loginCallbackHandler