#NextAuth integration
4 messages · Page 1 of 1 (latest)
Let me check the knowledge base for you. One moment! :books:
Yes, it is possible to integrate NextAuth with Convex, although it might require some custom setup. Here are some steps and resources that might help:
-
Set up a users table in Convex to store your users and sync relevant data from your auth provider. When a user signs up or logs in, get the Convex user based on the auth info. If there's no user, create one. Once you have a user from your Convex table, you can use that for any authorization across your app. For example, if you only want members of a given team to be able to view that team's projects, you can write a function that takes the current Convex user document and asserts team membership, and run that before executing a privileged query. There are helpers to make this a bit simpler too - Convex helpers, for example, gives a library and patterns for auth source (https://discord.com/channels/1019350475847499849/1219309150635294782).
-
There are some community examples of NextAuth integration with Convex. You can check out these GitHub repositories for reference:
- webdevcody/next-auth-convex (https://github.com/webdevcody/next-auth-convex)
- trace2798/convex_feedit (https://github.com/trace2798/convex_feedit)
- ThatGuyJamal/next-auth/ConvexDB-Adapter (https://github.com/ThatGuyJamal/next-auth/blob/ConvexDB-Adapter/packages/adapter-convex/src/index.ts)
- xipanca/nextjs-ts-nextauth-convex (https://github.com/xipanca/nextjs-ts-nextauth-convex) source (https://discord.com/channels/1019350475847499849/1219309150635294782)
-
If you're having trouble with NextAuth, you might consider using a custom JWT token and use this approach for Convex: Custom Auth (https://docs.convex.dev/auth/custom-auth) source (https://discord.com/channels/1019350475847499849/1206723995781832765).