03 - Getting a Token
Last updated
Last updated
Let's just create a function that will get our token and print it in the console.
It is often handy to have a function that retrieves the session token. Let's write a basic token. You can add this directly under our last function in 02-user-scripts.js
:
Save and run the app. If you call the function in the console, it will print:
This is handy for passing the token around in our app, but it's also handy to access the token for testing purposes.
Another way to access your token is simply by calling the localStorage.getItem("SessionToken")
method:
Note that we've made a spot in the DOM for the getSessionToken()
method. Let's test that:
Make sure that both the server and client are running.
Open the console.
Go to Step #8: Function: Get Session Token on the table.
Click the button to print the token to the console: