Authentication with prisma and apollo feels hard t...
# orm-help
n
Authentication with prisma and apollo feels hard to grasp
n
Can you describe the hard parts to grasp? šŸ™‚
n
There is a lot moving parts some of the code bit advance I'm currently looking the docs https://www.prisma.io/docs/reference/upgrade-guides/graphcool-to-prisma/authentication-and-authorization-yaeco6ieth/ and https://www.apollographql.com/docs/react/recipes/authentication.html Trying to piece together those two. I know that the howtographql goes through the authentication really well but that's a lot code to write just to setup a an authentication.
Sometimes you just have come across the right tutorials like learning the render props for apollo and manually handling the caching after a mutation. I found out this great blog article that helped me out https://www.prisma.io/blog/tutorial-render-props-in-react-apollo-2-1-199e9e2bd01e/ The should be a similar for auth with prisma and apollo maybe like a really basic version. I know that not everybody uses apollo as client but I think majority does. Again going back to the original question whats hard. You are writing a lot of boilerplate code sort of speaking sometimes if feels your hacking your own solution(creating utils). The token parts is maybe what causes bit confusion for me cannot really tell. Authentication is one of those core functionality that every app at some point has to have one. I saw that there is an example on github https://github.com/prismagraphql/prisma/tree/master/examples/authentication It doesn't however include apollo which is a bummer.
z
was in the exactly same place last week, this boilerplate helped me a lot https://github.com/graphql-boilerplates/react-fullstack-graphql/tree/master/advanced
šŸ‘ 1
it turned out to be much easier than I had thought
if you want to go for auth0 then there's this https://github.com/coformatique/prisma-auth0-starter
šŸ‘ 1
I did spend a few hours first learning about session-less authentication and JW-token in general...
n
@zonofthor Thanks for answering, appreciate all help I can get. I'm simple guy looking for simple solution
z
np, there's not so much going on in Apollo to authenticate except that you use ApolloLink to add token to the http requests, as seen in the boilerplate and you can read about it here https://www.apollographql.com/docs/react/recipes/authentication.html#Header
n
yeah I figured that out with ApolloLink to add token to the http requests part. The example that you provided https://github.com/graphql-boilerplates/react-fullstack-graphql/tree/master/advanced Is probably the closest thing to what I want. I love that its part of the advanced example. My question is that can you make that simpler? and if so, is there an example on it One thing I noticed with example is that it's using HOC rather than the render props which could be somewhat of adjustments if you are use to the newer tutorials.
z
you can choose basic, minimal or advanced boilerplate https://github.com/graphql-boilerplates/react-fullstack-graphql
IMHO, HOC or render props is just a matter of personal choice
you can easily convert between them
h
Authentication its not simple topic, if you want to do it correctly. There is a lot of problems what can appear.
If you make simpler solution its not correct one and its almost like having no authentication.
šŸ‘ 1
l
Basic server GraphQL auth is simple (it's just express middleware), but it gets tricky the further down the hole you go. In my app, I'm working with Auth0, NextJS, client token refetching, and authenticated subscriptions. I'm not there yet. But as I learn, I'm also updating my starter repo. Check out https://github.com/LawJolla/prisma-auth0-example with the next-js branch. It's not working (yet), but you can see where I'm headed in the code.
n
@lawjolla thanks man! I’m going to look into it, many people here have suggested auth0 and it one of those that pops up on google.
Have done more digging in this topic, sat all night with this repo https://github.com/prismagraphql/prisma/tree/master/examples/authentication Little bit hard to follow the code in fact last night I consider to purchase this https://quokkajs.com/pro/ just to help me out. It seems that there's a middleware https://github.com/Volst/graphql-authentication Here is an example repo https://github.com/prismagraphql/prisma/tree/master/examples/graphql-authentication
h
What is so hard to follow? Where you got lost? There are two resolvers, one creating new user and his password with
bcrypt
then you have loging what compare password you send with stored one
Plus you have checking jwt token if its valid šŸ™‚ and nothing more to it
If you don't know how jwt tokens works or bcrypt you need to learn basics, there is no possibility to create something like this if you don't know basic stuff what everything is build on top of.
l
P.s. I bought Quokka pro and love it