Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export NextAuthRequest type from next-auth root #12207

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mahady-manana
Copy link

☕️ Reasoning

Hello,
the NextAuthRequest type is not exported from next-auth, but it is very useful to be able to import it in your code when working with next api route.

There are many reason for it to be useful, but the most common, I think, is when you forward the req params of auth(req => {...}) in api route.

export const POST = auth((req) => {
  try {
    const searchParams = req.nextUrl.searchParams;
    const query = searchParams.get("q");
    switch (query) {
      case "create-x":
        return createSomeStuff(req); // if you want this function typed
      case "create-y":
        return createSomeStuffss(req); // if you want this function typed;
      case "create-z":
        return createSomeStuffssxx(req); // if you want this function typed;
      default:
        break;
    }
  } catch (error) {
    // catch
  }
});

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

📌 Resources

Copy link

vercel bot commented Nov 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2024 1:38pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Nov 9, 2024 1:38pm

Copy link

vercel bot commented Nov 9, 2024

@mahady-manana is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant