graphile / starter

Opinionated SaaS quick-start with pre-built user account and organization system for full-stack application development in React, Node.js, GraphQL and PostgreSQL. Powered by PostGraphile, TypeScript, Apollo Client, Graphile Worker, Graphile Migrate, GraphQL Code Generator, Ant Design and Next.js
https://graphile-starter.herokuapp.com
Other
1.74k stars 219 forks source link

Setting up Separate endpoint for APIs with Socket #282

Closed riddhiftw closed 2 years ago

riddhiftw commented 2 years ago

Summary

While trying to setup /api for API only auth, not able to get websocket working for /graphql.

Additional context

I set up /api as separate express instance and managed plugins including passport for that, I am keeping web with session authentication and JWT for api authentication.

While I get graphql endpoint for /graphql and /api/graphql but websocket is only being enabled with one of the endpoint. Not getting idea as what I should do for this?

I would like to hear other ways as well if its possible to implement both type of authentications without doing something so silly that I did.

benjie commented 2 years ago

Why two separate express instances?

riddhiftw commented 2 years ago

Thing is I am using /graphql for web endpoint which use middleware and authentication with session, while mobile application is being authenticated with JWT Token only. What should be possibilities other than this?

benjie commented 2 years ago

There's no particular reason you can't support JWT and sessions on the same endpoint - what issue are you facing when you try and do this?

riddhiftw commented 2 years ago

Issue is that when I am attaching JWT middleware, I am getting unauthorized, if I don't add JWT headers, while in API case session cookies won't be there. So I am bit confused as how to merge these two.

benjie commented 2 years ago

You're probably looking for the credentialsRequired: false option to the JWT middleware. https://github.com/auth0/express-jwt#error-handling

riddhiftw commented 2 years ago

Ah, it was that simple, Thanks @benjie for the help.