Ansopedia Creator Studio (ACS) is an open-source content management system (CMS) designed to power Ansopedia, a learning platform. It provides a user-friendly interface for creating, editing, and managing various content types like posts, comments, questions, quizzes, and assets (images, files).
MIT License
1
stars
2
forks
source link
[Hacktoberfest] Feature Request: Implement Token Verification with `api/v1/auth/verify-token` #10
Implement token verification in the Next.js app using api/v1/auth/verify-token to ensure that users accessing protected routes have valid tokens. Use Redux for state management, Axios for API calls, and React Query for handling verification.
Tasks
Implement Server-Side Token Verification:
In getServerSideProps for protected pages, extract accessToken from cookies.
Make a server-side request to api/v1/auth/verify-token using Axios to validate the token.
Redirect users to the login page if the token is invalid.
Create a useAuth Hook for Client-Side Verification:
Use useSelector to access accessToken and isAuthenticated from Redux.
Create a useAuth hook that wraps useQuery to verify the token using api/v1/auth/verify-token on the client side.
Redirect to the login page if the user is not authenticated.
Set Up Middleware for API Route Protection:
Use Next.js middleware to validate tokens for API routes, ensuring that only authorized users can access specific server-side functionalities.
Return appropriate status codes and messages for unauthorized access attempts.
Acceptance Criteria:
Protected routes are accessible only to users with valid tokens.
Invalid tokens trigger a redirect to the login page.
The verification process is efficient and integrates seamlessly with Redux and React Query.
Description
Implement token verification in the Next.js app using
api/v1/auth/verify-token
to ensure that users accessing protected routes have valid tokens. Use Redux for state management, Axios for API calls, and React Query for handling verification.Tasks
Implement Server-Side Token Verification:
getServerSideProps
for protected pages, extractaccessToken
from cookies.api/v1/auth/verify-token
using Axios to validate the token.Create a
useAuth
Hook for Client-Side Verification:useSelector
to accessaccessToken
andisAuthenticated
from Redux.useAuth
hook that wrapsuseQuery
to verify the token usingapi/v1/auth/verify-token
on the client side.Set Up Middleware for API Route Protection:
middleware
to validate tokens for API routes, ensuring that only authorized users can access specific server-side functionalities.Acceptance Criteria: