ansopedia / creator-studio

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

Open sanjaysah101 opened 6 days ago

sanjaysah101 commented 6 days ago

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

  1. 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.
  2. 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.
  3. 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: