MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Help with Mongo Realm and NextJS with User Authentication?

Hello. I’m new to Mongo, and Next JS.
I read the article on How to Integrate MongoDB Into Your Next.js App today and now I’m looking for more!

I’d like to build a NextJS app that uses Realm for user authentication with protected API routes for user data. Does anyone have a link to an tutorial article, or Github Repo or any other resources to do this?

Looking forward to your responses.

Hey Brian - While I don’t think we have one, it seems like Vercel has an example of using Realm with Next.JS. Would this help? - https://github.com/vercel/next.js/commit/1b5ca788104323d2851e70e7b4682ec815faca4a

I will take a look when I can.

Hey Brian,

Depending on your approach to authentication, you’d either use the Realm Web SDK or the Node.js SDK. But when it comes to Auth, are you trying to use Realm solely for auth or do you need other realm features in your app. The only reason I ask is that if you just need user authentication, a specific library like Next-Auth could be a better choice.

1 Like

I’m planning to build a Admin/Dashboard app for authenticated users only. Non-authenticated users will only see a logon screen.

I would love to use NextAuth if it supports Realm features. Other developers in my company are working with Realm for other, non-Next JS apps, so I think I need to find a way to tie into Realm for authentication.

Does NextAuth work with Realm?

Hey Brian - not sure what your implementation details are for auth in the other apps, but it seems like NextAuth would work with Realm if you use JWT Authentication. After using NextAuth to sign in, you can pass in the JWT that you get from the callback to Realm’s JWT Auth provider