silexlabs / Silex

Silex live web creation, free/libre no-code website builder, next gen Webflow for the static web
http://www.silex.me
GNU Affero General Public License v3.0
2.24k stars 578 forks source link

before middleware generates an infinite redirect loop #465

Closed DaveSanchez closed 8 years ago

DaveSanchez commented 8 years ago

Hi, I'm new with silex and I'm trying to build a simple login and register system. I wrote a before middleware that checks if a user session variable is set, if it's true it means that user is already logged in, otherwise is not and it must be redirecting to the home page where only a login form is visible.

`<?php

$app->before(function () use($app) {

// Checa si ya existe una sesion 'user' existente en variable $userisloggedin = is_null($app['session']->get('user')) ? false : true;

//Da valor bool a la variable auth de Silex para saber que mostrar si hay o no una session $app['twig']->addGlobal('auth',$userisloggedin);

if(!$userisloggedin) { return $app->redirect($app["url_generator"]->generate("home")); }

});`

The problem is, when redirects to the home page, the user session is not exists yet, so it's redirecting over and over again to the home page and generates an error which is The page isn't redirecting properly

so I would like to know if it is possible to omit the home route for this middleware or what would be a solution for this. Sorry if my english is not good. Thank you!

singchan commented 8 years ago

Hello Here this is about silex website builder Your question seems to be about the php framework