A common challenge when building apps is setting up authentication. If our apps have user-specific data, we need a way to secure that data and identify our users so they can access their own information.
Authentication in Gatsby
We regularly get questions about how to add authentication to Gatsby, and while we have simple examples that wouldn’t help in a production app and the more complex logic of our store, we don’t have a straightforward, “here’s how to add authentication for a user account page in Gatsby” example.
On a recent livestream, Ado Kukic helped me create an example for setting up auth for a Gatsby account page.
This is part of the Learn With Jason series, which streams live on Twitch every Thursday at 9 am Pacific.
On the stream, we covered:
- How to create dynamic routes in Gatsby
- How to use Auth0 to require a user login to view certain areas of a Gatsby site
- How to store user tokens in a secure way
- How to keep users logged in between page loads securely
The code we built is available on GitHub and will serve as a great starting point if you need to create a Gatsby app with user accounts.
Additional links and resources
- Adding App Functionality with Gatsby
- Simple auth example in Gatsby
- Source code for the Gatsby store, which uses Auth0 to authenticate users
- Source code for the Gatsby store API, which uses Auth0 to authenticate requests
- Docs for the
- Ado Kukic on Twitter
- Jason Lengstorf on Twitter
Watch future livestreams
There’s a new livestream every Thursday at 9 am Pacific. The streams are even more fun live with the chat, so join in and let’s learn together!
- Click the “follow” button on my Twitch account to get notified when streams start
- Check the “Upcoming Streams” section to learn who’ll be joining me to teach us
- Send me ideas on Twitter for who you’d like to see on the stream
See you on the next stream!