Auth with passport.js

Evening all,
Has anyone successfully setup trpc with passport.js for auth?
Rammstein489d ago
Any progress regarding this? I am facing a similar challenge
mark salsbery488d ago
What particular issues using passport auth with tRPC? While passport auth may not fit with tRPC APIs, it can certainly be used with tRPC. With tRPC middleware, context, and custom links one has pretty good access to the request/response pipeline when using the Express adapter, so it's pretty flexible
Unknown User460d ago
Nick460d ago
tRPC expects a middleware to return I haven't used passport, but if passport returns the result of the next which you're passing to it, you can just add a return, and then might need to pass something like () => to it
Nick460d ago
The docs are worth a read:
Middlewares | tRPC
You are able to add middleware(s) to a procedure with the t.procedure.use() method. The middleware(s) will wrap the invocation of the procedure and must pass through its return value.
mark salsbery460d ago
@NT I don’t think you can use Express (connect) middleware directly as tRPC middleware (I could be wrong). I would put the Passport middleware in an Express router before the tRPC adapter
Nick460d ago
That's also a good point if it's designed for Express. Probably there are some lower level APIs you could use to build a tRPC middleware via Passport, or someone has published one already. I wouldn't hoist the middleware up out of tRPC in most cases though; you might want to vary how auth is handled based on the procedure in the future
mark salsbery459d ago
For me I use a hybrid of Express and tRPC routers. Super flexible, and for Passport, it depends on which authentication strategy I’m using. For basic authentication and tokens I just roll my own. For more complex strategies I’ll hoist Passport to Express and expose whatever I need in tRPC context/middleware
More Posts
Object keeps getting overwrittenI feel like i'm missing something fundamental here. when I add a new entry into object ``b`` it resAccessToken for API callsWhat would be the best approach to pass the AccessToken from NextAuth Session to the Http Client whiRequest or Response Specification Definition DocumentI am developing a backend service using trpc, but I need to dispatch trpc in another programming lanabortOnUnmount config errorI'm encountering an error when passing abortOnUnmount saying that it does not exist as a possible pazustand + trpc (basic data fetching)im trying to use zustand with trpc, but having trouble setting some data to global state. What am i TypeError Cannot destructure property 'abortOnUnmount' of 'useContext(...)' as it is null.Zero Clue what is error mean exactly....First time learning trpc really good tool. help with setting cookies on front end.Hello how do you use tRPC to make a cookie and send it to the front end. or is there any other methoHow do we add settings in each query like before?Since the new update, bee super confused. I used to do this, and can't recreate it now. ``` const Handling error globallyAccording to the docs on errors I should get such error objecant access trpc endpoints via the browseri'm converting some express endpoints to trpc, and I cant figure out how to access my endpoints via tRPC without SSRWhen using tRPC with ssr it uses `getInitialProps`, which has kinda of a cool effect in terms how a trpc + expo react native issueDoes anyone know how to solve this? Im not familiar with webpack at all. I’m a junior frontend.Can you chain middlewares in v10?Would I be able to make a rate limit and isAuthed middleware, then put queries behind both middlewarLoad data client-side via react-query while using tRPC with SSRIs there any way to load data client-side when using tRPC? I want my page to be rendered and load daServing clients in another repository?Would it be possible for tRPC to act as a server for clients in another repository and if so how wouHow to execute mutation outside of react context?Hi! I'm slowly converting code over to v10 - looks great! However, I ran in to an issue when using tWhen not to use tRPC?Is there any scenario when building a mobile and/or a web app with backend that you would not recommBi directional infinite query example with prismaI'm working on a project that is using this pattern, but my `hasPreviousPages` gets blown away when