lib/hapi-auth.js
function cmd_logout (msg, respond) {
    var req = msg.req$

    // get token from request
    req.seneca.act("role: 'auth', get: 'token'", {tokenkey: options.tokenkey}, function (err, clienttoken) {
      if (err) {
        return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
      }

      if (!clienttoken) {
        return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
      }

      clienttoken = clienttoken.token
      // delete token
      req.seneca.act("role: 'auth', set: 'token'", {tokenkey: options.tokenkey}, function (err) {
        if (err) {
          return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
        }

        req.seneca.act("role:'user',cmd:'logout'", {token: clienttoken}, function (err) {
          if (err) {
            req.seneca.log('error ', err)
          }
          req.cookieAuth.clear()
          delete req.seneca.user
          delete req.seneca.login
          return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
        })
      })
    })
  }
function cmd_logout (msg, respond) {
    var req = msg.req$

    // get token from request
    req.seneca.act("role: 'auth', get: 'token'", {tokenkey: options.tokenkey}, function (err, clienttoken) {
      if (err) {
        return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
      }

      if (!clienttoken) {
        return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
      }

      clienttoken = clienttoken.token
      // delete token
      req.seneca.act("role: 'auth', set: 'token'", {tokenkey: options.tokenkey}, function (err) {
        if (err) {
          return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
        }

        req.seneca.act("role:'user',cmd:'logout'", {token: clienttoken}, function (err) {
          if (err) {
            req.seneca.log('error ', err)
          }
          req.cookieAuth.clear()
          delete req.seneca.user
          delete req.seneca.login
          return req.seneca.act('role: auth, do: respond', {err: err, action: 'logout', req: req}, respond)
        })
      })
    })
  }
function cmd_logout ( msg , respond ) { var req = msg . req$ // get token from request req . seneca . act ( "role: 'auth', get: 'token'" , { tokenkey : options . tokenkey } , function ( err , clienttoken ) { if ( err ) { return req . seneca . act ( 'role: auth, do: respond' , { err : err , action : 'logout' , req : req } , respond ) } if ( ! clienttoken ) { return req . seneca . act ( 'role: auth, do: respond' , { err : err , action : 'logout' , req : req } , respond ) } clienttoken = clienttoken . token // delete token req . seneca . act ( "role: 'auth', set: 'token'" , { tokenkey : options . tokenkey } , function ( err ) { if ( err ) { return req . seneca . act ( 'role: auth, do: respond' , { err : err , action : 'logout' , req : req } , respond ) } req . seneca . act ( "role:'user',cmd:'logout'" , { token : clienttoken } , function ( err ) { if ( err ) { req . seneca . log ( 'error ' , err ) } req . cookieAuth . clear ( ) delete req . seneca . user delete req . seneca . login return req . seneca . act ( 'role: auth, do: respond' , { err : err , action : 'logout' , req : req } , respond ) } ) } ) } ) }
LOGIN END LOGOUT START
LOGIN END LOGOUT START