How can I log in a user in Craft 3 and redirect to a url?
This doesn't work:
$username = $user->username;
$userCode = $user->teamCode;
Craft::$app->user->login($username, $userCode);
Thanks!
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityHow can I log in a user in Craft 3 and redirect to a url?
This doesn't work:
$username = $user->username;
$userCode = $user->teamCode;
Craft::$app->user->login($username, $userCode);
Thanks!
Documentation for this can be found in Craft's class reference.
# Login as user, by id
Craft::$app->getUser()->loginByUserId($user->id);
# Redirect
return Craft::$app->getResponse()->redirect($url)->send();
Or, if you're in a controller:
return $this->redirect($url);