diff --git a/lib/authentication/Manager.php b/lib/authentication/Manager.php
index d9c9f95927f2c1ff5f104afcf8cb358b08b0eecb..b25efadf9d056b6bab87b6b831f2d9fed4d1b972 100644
--- a/lib/authentication/Manager.php
+++ b/lib/authentication/Manager.php
@@ -55,7 +55,7 @@ class Manager
                 Metrics::increment('core.sso_login.attempted');
                 // then do login
                 $authplugin = StudipAuthAbstract::GetInstance($provider);
-                if ($authplugin) {
+                if ($authplugin instanceof \StudipAuthSSO) {
                     $authplugin->authenticateUser('', '');
                     if ($authplugin->getUser()) {
                         $user = $authplugin->getStudipUser($authplugin->getUser());
@@ -71,8 +71,8 @@ class Manager
                         }
                         Metrics::increment('core.sso_login.succeeded');
 
-                        sess()->regenerateId(['auth', '_language', 'phpCAS', 'contrast']);
                         $this->setAuthenticatedUser($user);
+                        sess()->regenerateId(['auth', '_language', 'phpCAS', 'contrast']);
                     }
                 }
             }