JWTs let two parties securely send information as a JSON object. A token has a header, payload, and signature, and is commonly sent in an Authorization header using the Bearer scheme. After login, the token can accompany requests to resources the user is allowed to access.
Authentication
Learn Next.js presents a Mastering Next.js module on JWTs, Auth0, and Firebase authentication for the Day Drink application.
Learn Next.js walks through a Next.js Auth0 example that uses API routes and a hook to fetch and store user information. The module uses Firebase for Day Drink, citing prior familiarity, its broader platform features, user management dashboard, and simpler setup for this example. Firebase creates signed ID tokens for users in a project.
The Firebase integration is organized in a custom `useAuth` hook that exposes the current user and methods for signing in, signing up, and signing out. A context shares user state across the app, while an auth state listener updates that state and returns an unsubscribe function. The example uses email and password, with password reset mentioned as another possible method.
The sign-in page combines `useAuth`, Chakra UI toast messages, and the Next.js router to show Firebase errors or redirect successful users to the deals page. React Hook Form manages required email and password fields, submission state, and validation errors. The form logic lives in a reusable component that can appear in a full-screen page or a modal when someone tries to vote or add a deal while logged out.
Learn Next.js closes by noting that Firebase and Auth0 can provide prebuilt or hosted login interfaces, reducing the amount of form code to maintain. Custom forms take more work but give the team control over branding and behavior. The Day Drink example uses custom flows built from Firebase, a hook, and reusable components.
Takeaways
- Treat a JWT as a signed token with a header, claims payload, and signature, and send it with requests that need authentication.
- Choose an auth provider based on project needs: the example favors Firebase for its simpler integration and broader platform features.
- Keep user state and auth actions behind a reusable hook so pages and protected components can share the same flow.
- Use form validation and clear error feedback for sign-in, and redirect only after authentication succeeds.
- Decide whether prebuilt login screens or custom forms better fit the team's maintenance needs and branding.
Mentioned in this talk
Search inside this talk
What was claimed 8
- featureJWT: Has a header, payload, and signature
“Those parts are a header, a payload, and a signature.”
YouTube Unverified1 source· Talk
- integrates with
“it works with Next.js”
YouTube Unverified1 source· Talk
- uses
“I chose to use Firebase instead of Auth0 for the example application”
YouTube Unverified1 source· Talk
- feature
Firebase: Provides authentication, Cloud Storage, and a real-time database
“not only authentication, but also Cloud Storage”
YouTube Unverified1 source· Talk
- uses
“Firebase uses JWTs for authentication.”
YouTube Unverified1 source· Talk
- uses
“useToast from Chakra”
YouTube Unverified1 source· Talk
- usesDay Drink uses React Hook Form
“I'm calling the useForm hook”
YouTube Unverified1 source· Talk
- integrates withFirebase UI integrates with
Firebase
“you can just use Firebase UI components”
YouTube Unverified1 source· Talk
Related talks
50:44
11:31
21:00
6:35
26:31
14:29