});
$app->post('/app/create', function () use($app, $twig, $assets, $MongoUser) {
    $_user = array('_id' => uniqid(), 'email' => $app->request()->post('email'), 'password' => $app->request()->post('password'));
    $new_user = $MongoUser->save($_user);
    if ($new_user) {
        // redirect to login page
        $dataArray = array('user' => $new_user, 'message' => "User created sucessfully");
        //$response = json_encode($dataArray);
        //echo $response;
        if (!isset($_SESSION)) {
            session_start();
        }
        $cookie_data = json_encode($new_user, true);
        $_SESSION['app_id'] = $cookie_data;
        $app->redirect('/app');
    } else {
        $app->halt(401, "User sign up fail.");
    }
});
/*
$app->get('/app/create', function() use ($app, $twig, $assets) {
  // so here I need to call the API.
  echo "hi";
});
*/
// this is used as my default function
$app->notFound(function () use($app, $twig, $assets) {
    $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets);
    echo $twig->render('views/404.php', $data);
});
$app->run();