Learning Tutrial Chapter 14, and "authorized" in callbacks config of auth.config.ts by using NextAuth is not triggered. #13320
Replies: 1 comment
-
|
@gaomigithub It seems like you've gotten the auth.config.ts mixed up with the Middleware. The setup you showed is incorrect. First of all, the callbacks object is a set of methods (authorize(), jwt(), session()) that are designed to act as a callback function for when the actual functions are invoked. For example, you have page access logic inside the authorize() callback. This callback only runs once, and only when a user signs in. This means that if I refresh the site, of course it wont run as the user already has a cookie. Furthermore, you will need to setup the actual authorize() function that handles the signIn() logic. ==> All access / permission related logic should be put in the middleware.ts file, as it runs on every request. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My repo
Hello guys,
I am currently learning about Next course from offical site and doing Chapter#14 (Adding Authentication). Other features such as "login" and "signout" learned from C#14 work good.
When I am testing what I did by learning at Protecting your routes with Next.js Proxy
This feels like nothing happened. I still can direct to any URL and not being redirected to login page.
Tried some search on Google and AI but they all tell me I did correct and should be work.... Also, I can not find the log I left inside authorized. I am really confused right now.
I pushed my codes wrote in this Chapter with commit name: "Chapter 14: Adding Authentication; todo: something wrong with authConfig".
Please give me any hint you find.
Thank you soooo much!!!
Beta Was this translation helpful? Give feedback.
All reactions