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

Protected tRPC router example? #191

Closed
t3dotgg opened this issue Jul 14, 2022 · 6 comments · Fixed by #194
Closed

Protected tRPC router example? #191

t3dotgg opened this issue Jul 14, 2022 · 6 comments · Fixed by #194
Assignees
Labels
🔰 good first issue Good for newcomers 🙋‍♂️ help wanted Extra attention is needed

Comments

@t3dotgg
Copy link
Member

t3dotgg commented Jul 14, 2022

Might be less relevant post-v10

Including this would make my life much easier

import * as trpc from "@trpc/server";
import { createRouter } from "./context";

export function createProtectedRouter() {
  return createRouter().middleware(({ ctx, next }) => {
    if (!ctx.session || !ctx.session.user) {
      throw new trpc.TRPCError({ code: "UNAUTHORIZED" });
    }
    return next({
      ctx: {
        ...ctx,
        // infers that `session` is non-nullable to downstream resolvers
        session: { ...ctx.session, user: ctx.session.user },
      },
    });
  });
}
@t3dotgg
Copy link
Member Author

t3dotgg commented Jul 14, 2022

Example of how much code I could delete pingdotgg/PingAsk@73fd75d

@nexxeln
Copy link
Member

nexxeln commented Jul 14, 2022

Oh yeah we can do this. Are you free to make a PR?

@t3dotgg
Copy link
Member Author

t3dotgg commented Jul 14, 2022

Oh yeah we can do this. Are you free to make a PR?

Not particularly :( will mark it as "good first issue" so someone else can take it if you're down

@nexxeln nexxeln added 🔰 good first issue Good for newcomers 🙋‍♂️ help wanted Extra attention is needed labels Jul 14, 2022
@bhatvikrant
Copy link
Contributor

bhatvikrant commented Jul 14, 2022

Hey folks, can I pick this up?
// @nexxeln @theobr

@nexxeln
Copy link
Member

nexxeln commented Jul 14, 2022

Hey folks, can I pick this up? // @nexxeln @theobr

Feel free, should I assign you?

@bhatvikrant
Copy link
Contributor

Hey folks, can I pick this up? // @nexxeln @theobr

Feel free, should I assign you?

Yes please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔰 good first issue Good for newcomers 🙋‍♂️ help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants