Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Now that we have the JWT ready, we will use the HTTP Foundations package to set and retrieve cookies.
NOTE: Because we set our extra parameter to accept an array, make sure you pass the cookie as an array.
Tips for Reading and Writing Cookies
To test reading a cookie after login: on index.php
if (request()->cookies->has('access_token')) {
echo "logged in";
} else {
echo "not logged in";
}
If the cookie isn't working properly, one of the most common reasons is that the COOKIE_DOMAIN in the .env file is not set properly.
When using workspaces it should be YOUR workspace url, which would look something like
COOKIE_DOMAIN=port-80-m1m8flu0vu.treehouse-app.com
When working locally, it should be
COOKIE_DOMAIN=localhost
You need to sign up for Treehouse in order to download course files.
Sign up