Skip to content

feat(web): add protected API endpoint /api/dev/test using requireAuth…#55

Open
Niksinikhilesh045 wants to merge 2 commits intoharshlocham:mainfrom
Niksinikhilesh045:feat/protected-api-test
Open

feat(web): add protected API endpoint /api/dev/test using requireAuth…#55
Niksinikhilesh045 wants to merge 2 commits intoharshlocham:mainfrom
Niksinikhilesh045:feat/protected-api-test

Conversation

@Niksinikhilesh045
Copy link
Copy Markdown

Add protected API endpoint /api/dev/test

Summary

This PR introduces a protected API route in the web application to validate and demonstrate the existing authentication flow.


What’s added

  • New endpoint: /api/dev/test
  • Implemented using Next.js App Router
  • Secured using requireAuthUser

Behavior

  • If authenticated:

    {
      "success": true,
      "userId": "<authenticated_user_id>"
    }
  • If not authenticated:

    • Returns standardized auth error response (e.g., AUTH_ACCESS_TOKEN_MISSING)

Purpose

  • Validate cookie-based authentication flow (access token handling)
  • Ensure requireAuthUser works correctly in protected routes
  • Provide a reference implementation for future secure endpoints

Testing

  • Tested via browser console:

    fetch("/api/dev/test", { credentials: "include" })
  • Verified:

    • Successful response when logged in
    • Proper error response when unauthenticated

Notes

  • No changes made to existing auth logic
  • No environment or config changes required
  • Endpoint is intended for development/testing and can be extended for future features

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 4, 2026

@Niksinikhilesh045 is attempting to deploy a commit to the harshdeepsinghlocham's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new protected Next.js App Router endpoint in the web app to exercise the existing auth guard flow, while also introducing a couple of repo/tooling updates that support the web workspace.

Changes:

  • Adds /api/dev/test, a protected GET route that calls requireAuthUser and returns the authenticated user id.
  • Updates the web build script to use cross-env and adds the dependency to the web workspace.
  • Changes Turbo dev task orchestration and refreshes the root lockfile/workspace package metadata.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
turbo.json Makes dev depend on upstream build tasks across the workspace.
package-lock.json Updates lockfile entries for the new web dependency and workspace package metadata.
apps/web/package.json Switches the web build script to cross-env and adds cross-env as a dev dependency.
apps/web/app/api/dev/test/route.ts Adds the new protected /api/dev/test API route returning { success, userId }.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +8
export async function GET() {
const guard = await requireAuthUser();
if (guard.response) {
return guard.response;
}
Comment on lines +5 to +7
const guard = await requireAuthUser();
if (guard.response) {
return guard.response;
Comment thread turbo.json
Comment on lines +36 to +38
"dependsOn": [
"^build"
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants