ā tRPC failed on partition.getAll: UNAUTHORIZED
Hello gentle-men/waman, i have been struggling with implementing a custom credential provider the last two days.. haven't slept properly.. and now i must admit i need assistance. I have successfully implemented the "login/nextauth" part of the job, in the client side.. but when i call my queries from client i get
ā tRPC failed on partition.getAll: UNAUTHORIZED
.. I think the solution is that i somehow get my session from useSession() send to TRCP or auth by TRCP, but i dont know... thats what been bugging me the last 48 hours.. please some kind soul.. HELP MEE š¤Æ P.S it think has something to do with the way the protected procedure autheticates a user. P.P.S if you need any futher information. Please dont hesitate to ask me. Thanks in advance!!
19 Replies
owo7 are you calling the procedure after useSession has finished authenticating on the client side (using enabled in the useQuery call)
this is how i do
am i doing something wrong?
that looks good to me, maybe the shape of the session was changed somehow on the server side then, have you tried console logging the ctx in the protectedProcedure middleware
yeah when i do that i just get null
for the entire ctx or just session :3?
ah srry was looking inside getSeverAuthSession at ctx xd, not sure whats going wrong then ill try setup cred provider to see
thanks for the help man really appreciate it !! im losing my mind here XD also pretty new to the stack š
I am going to sleep its 3 AM here in DK, if you have any input or solution please post it here i will look at it first thing in the morning š
The trpc api routes seem to be working for me using creds,
If your getting the session with the correct shape on the client side then only thing I can think of is missing NEXTAUTH_SECRET env variable, you can set it in the .env file and then in authOptions in 'src/server/auth.ts' https://next-auth.js.org/configuration/options#nextauth_secret
Alternatively you could try using the getToken method instead of getServerSession inside of getServerAuthSession to see if the token is valid then could be some problem with getting the session from the token on the server.
https://next-auth.js.org/tutorials/securing-pages-and-api-routes#using-gettoken
I'm new to stack aswell is pretty cool : D, hope u had good sleep lmk results OwO.
Securing pages and API routes | NextAuth.js
You can easily protect client and server side rendered pages and API routes with NextAuth.js.
Options | NextAuth.js
Environment Variables
i cant seem to get it working, i would love to have a look at your code if its possbile, to see if missed something. Do you have it on github?
can put it up sec
GitHub
GitHub - ja-iy/t3-cred-test
Contribute to ja-iy/t3-cred-test development by creating an account on GitHub.
make this .env file
then run
npm install
npx prisma migrate dev
npm run db-seed
the username and passowrd to login are in the seed file '/prisma/seed.ts'
i get this error `
when running prisma migrate dev
i am using mongodb as databse
ive only used mysql / sqlite so not sure what steps need to setup mongoDB srry
if want can get in a call and share screen to try help
Yeah sure, thanks alot! i only have about 20 min, so hopefully can get it done in that time
Should i call you?
oki