From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Customize token with JWT callback - Next.js Tutorial
From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch
Customize token with JWT callback
All right, guys, so we have a working authentication system. And there is one more thing I want to do before we end this section and go into the shopping cart. And that is add a JWT callback. Because right now, what happens is we get a JSON Web Token sent to the client when we log in. And then that token is sent to the server with every request. And that's what establishes and keeps that authentication and how it knows which user we are. Now, by default, that token has some data in it, like the user ID. But if you want to customize that, which we do, for instance, we want to add the user role to the token, because we're going to need that later, then you have to create a callback called JWT. Now, this callback is called whenever a JSON web token is created, so when you sign in, or updated whenever a session is accessed. And basically, we can set values to it. In this case, they're setting an access token and an ID set to account access token profile ID, most likely the Google…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Section intro2m 57s
-
(Locked)
Prisma user-related models9m 45s
-
(Locked)
Seed user data7m
-
(Locked)
NextAuth setup17m 31s
-
(Locked)
NextAuth catch all API route4m 12s
-
(Locked)
Sign-in and sign-out server actions8m 27s
-
(Locked)
Auth layout and sign-in page6m 58s
-
(Locked)
Credentials sign-in form6m 39s
-
(Locked)
Hook up sign-in form9m 28s
-
(Locked)
Callback URL redirect4m 26s
-
(Locked)
User button and sign-out11m 48s
-
(Locked)
Signup Zod schema and action8m 15s
-
(Locked)
Sign-up page and form7m 35s
-
(Locked)
Sign-up error handling12m 40s
-
(Locked)
Customize token with JWT callback8m 19s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-