Manicraft1001
Manicraft1001
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
I'm pretty sure that I posted it here. Anyhow, I'll explain my findings: - The blog above is correct. When tRPC is in use, one must refactor the authentication options to a function and pass the request and response object. Since the TS types do not overlap well, the errors must be suppressed. - The JWT callback must be removed. After that, the two new callbacks, described in the blog above, must be added. Basically, the only thing hindering you from using credentials with sessions is, that they don't have built in session management. Therefore, you must implement your own. Deletion of the session works implicit and no changes for that are required. - Modifying roles and immediately checking for them works absolutely fine with sessions.
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Wait, didn't I post my solution here two days ago? Or did someone delete it?
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
I'll post updates here for my findings
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Not a viable solution :/
45 replies
TTCTheo's Typesafe Cult
Created by ACPixel on 4/25/2023 in #questions
PlanetScale deployments when using T3, prisma, and vercel
If you still can't find, what you're looking for, check out the CLI: https://vercel.com/docs/cli
5 replies
TTCTheo's Typesafe Cult
Created by ACPixel on 4/25/2023 in #questions
PlanetScale deployments when using T3, prisma, and vercel
If you use GitHub, you can build a pipeline yourself, migrate data and set up database connections as necessary. I do the same, but with a selfhosted Gitlab instance. Vercel has some pretty amazing guides on this: https://vercel.com/guides/can-i-use-self-managed-gitlab-with-vercel
5 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Thanks for your help so far 🙂
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Not a great idea in my opinion. I will try a few things out. It will probably take a few days, since most code snippets are outdated or not in combination used with tRPC
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Also, where do I get the adapter from?
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Ok, some updates here. It seems, that the reason why Oauth and credentials are mostly incompatible is, that the crdentials provider does not support database sessions by design. The next-auth team designed it like this. Therefore, the easiest way to use Credentials with Discord auth is using JWT. However, there is a workaround, in which you create and manage your own sessions for credential logins. I got this from the following blog: https://nneko.branche.online/next-auth-credentials-provider-with-the-database-session-strategy/ I started implementing pieces and at least my Discord login is working again. However, I need to refactor some of the code, as I need access to the raw requests and responses to read and write headers & cookies - that is also described in the blog. One thing, that is preventing me from doing that, is this function, which is the default for t3app:
/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
It seems that it isn't compatible with the advanced initialization. I will give it a shot to re-write myself. Sadly, none of the GH posts nor the blog uses this approach for the server auth session. I'll post my findings here
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
I'll post the solution here, when I figured it out, in case someone else has the same questions
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Yes, there was only Discord by default. But it sucks that next auth is so restrictive with credentials. I'll try out the things you suggested. Can I tag you when I have updates?
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
1. Thanks, I will look at the examples. So far, all examples I've looked, either use JWT or only Google Oauth - which is significantly different compared to Discord. 2. Yes. If you want, I can show more details / screenshots. Feel free to start the app yourself too! 3. Yea.... Sucks 4. Sure. I'll send you after work
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Thanks for your time btw. I was really disappointed the last few days, because none of my actions improved the state of the application. You're helping me out a lot 🙂
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
I suggest, that you maybe have a look at the code. I'm simply not able to get any reliable results with the JWT and there is too little documentation about sessions.
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
1. I've read this multiple times. All tutorials and guides seem to use JWT, but sessions seem to have major advantages. I do understand how the basics of JWT works, but I am not experienced enough that I would understand everything. If you look at my Prisma schema, I already have the exact same model Session. My problem is, that I don't know how to use it, build sessions, refresh sessions and let sessions expire. I feel like there is too little information on this in the documentation - hence I asked here. I use Prisma as a DB adapter - which is the default for t3app. I do not understand how this should be done. The documentation only mentions the basic usage of Prisma: https://authjs.dev/reference/adapter/prisma 2. Okay, got it. I already use Prisma - it seems to work pretty okay, but I can't retrieve the user ID, nor any other information in any of my tRPC procedures. 3. Thanks for the suggestion. I have debugged many hours within the last few days. I tried deleting callbacks, modifying the content returned by the callbacks and to return different data depending on what provider was used. I looked at it today with an experienced friend - he has no idea, why my sesions are not working as they should. The JWT is empty and we weren't able at all to put any payload in the token, even though we return data from the callbacks. 4. Okay, got it. I noticed, that it's possible to fetch the user for each request by the user id. But for that, the other issues I'm having are blocking (eg. Discord not having an ID).
45 replies
TTCTheo's Typesafe Cult
Created by Manicraft1001 on 6/21/2023 in #questions
Empty JWT payload, persisting role permissions and "jankiness" with next-auth
Hi, thank you for your detailed reply. I appreciate your time. Let me quickly read all pullet points and reply to them...
45 replies