Typo3: Per JS prüfen, ob fe_user im Frontend eingeloggt ist

Manchmal möchte man im Frontend prüfen, ob die fe_user-Session des Benutzers noch gültig ist und dann automatisch ausloggen. Das ist vor allem beim Single-Page-Applications (SPA) sehr hilfreich.

TypoScript Setup:

plugin.tx_myextension.settings {
   pidLogout = 344
}

logincheck = PAGE
logincheck {

   typeNum = 7780
   config {
      disableAllHeaderCode = 1
      xhtml_cleaning = 0
      admPanel = 0
      additionalHeaders = Content-type: text/plain
      no_cache = 1
      contentObjectExceptionHandler = 0
   }
   
   10 = COA_INT
   10 {
      20 = FLUIDTEMPLATE
      20.template = TEXT
      20.template.value = "login":{f:security.ifAuthenticated(then:1, else:0)},"redirect":"{f:security.ifAuthenticated(else:'{f:uri.page(pageUid:settings.pidLogout)}')}"
      20.settings < plugin.tx_myextension.settings
      stdWrap.wrap = {|}
   }
}

JavaScript (jQuery). page-id anpassen!

$(function() {
   setInterval( function () {
      $.getJSON('index.php?id=XXX&type=7780').done(function ( data ) {
         if (!data.login) {
            window.location = data.redirect;
         }
      });
   }, 10 * 1000);
});

4 Gedanken zu „Typo3: Per JS prüfen, ob fe_user im Frontend eingeloggt ist“

  1. Vielen Dank … das hat mir bei einem Problem schonmal sehr weitergeholfen.
    Wie kann ich eigentlich über eine eigene Extension in TYPO3 10 einen User einloggen?
    Gibt es da auch ein gutes Tutorial zu?

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.