var db = require('../models');
var User = db.User;
var Session = db.Session;

async function getAuthUser(sessionId) {
  var session;
  var user;
  if(sessionId != undefined) {
    session = await Session.findOne({
      include: User,
      where: {
        sessionid: sessionId
      }
    });
    if(session) {
      user = session.User;
      return user;
    } else {
      return;
    } 
  } else {
    return;
  }
}

module.exports = {
  getAuthUser,
};