2

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!

1 Answer 1

3

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);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.