Protected
Find out how you can make the pages and apis protected so that only the logged in users can access them.
Pages
All the pages under /dashboard/
are protected and only accessible to the logged in users. You can checkout the src/app/dashboard/layout.tsx
file to see how it is done. If you want to manually make any page protected, you can use wrap the page with the LoginProvider
component and pass true
to the onlyLoggedIn
prop.
API
You can make the api protected by using the authorize
function present in src/auth.ts
file. This function is used to check if the user is logged in or not. It takes the NextAuth
session as an argument and few options to authorize the user on the basis of team. You can checkout the src/app/api/login/route.ts
file to see how it is done.