Next-Auth with FaunaDB Dev Get Session Error

Hi

I asked this question over on Stack Overflow and was asked to post it here. Here’s the original question - next.js - Next-Auth with FaunaDB Dev Get Session Error - Stack Overflow. I won’t repost all the logs, but here’s the issue;

I’ve set up Next-Auth on my NextJS project to use FaunaDB. I’ve managed to get it working on my production environment, however, it seems to not be working on my development environment, which is using the Fauna Dev docker container rather than the cloud-based database.

Whenever I run the dev server, I get an error log containing the following;

https://next-auth.js.org/errors#fauna__get_session_error [NotFound: instance not found] {
  description: 'Set not found.',

The full log is in the original SO post.

I’ve followed the guide to set this up and continue to get the same error. I’ve removed and recreated the fauna docker container several times, still the same error. I also have some data that I can access in the local Fauna Dev database, so that seems to be set up fine. Also if I change my .env.local environment variables to the ones I use on production, it all works fine, but of course is then using the cloud database.

I was also asked to post the output for Paginate(Match(Index("session_by_token"), "<a valid token id>")). I don’t have a valid ID to run as the collection is empty on my Fauna Dev image, but if I copy/paste the above I get the following;

{ data: [] }

So it seems to me that the index is correctly set up, as it’s not throwing an error.

I’ve been trying to work this out for days, so any assistance would be greatly appreciated. Many thanks!

Hi @PaddyShiel89,

Just to make sure we’re covering all the possibilities, can you add a dummy session token to the collection and then run the Paginate(Match(Index("session_by_token"))) query again?

Looking at the log, the original error was a 404 on this query:

'{"get":{"match":{"index":"session_by_token"},"terms":"86b962d600c3f53d41d5140de6daed654a473e670a99943d7fb301a4fc86357e"}}'

But if the collection is empty then a 404 for a Get() based on that term seems appropriate. Adding some dummy data and testing against that will help narrow down what’s happening.

Cory

Hi Cory, thanks for the reply.

I added the following through Fauna Shell;

{
  ref: Ref(Collection("sessions"), "309441265519297024"),
  ts: 1631365037400000,
  data: {
    userId: '307946306265940166',
    expires: Time("2021-09-25T18:08:21.521Z"),
    sessionToken: '997b45bb432cfbc05901e9a92ae9d1ac36637246277ac05ad915fb00b8fc9130',
    accessToken: '9dbec0113a46bc6a0768e1a5b7baafac65a1fb0a29568bc11562cd58ad97d5b9',
    createdAt: Time("2021-08-26T18:08:21.517447Z"),
    updatedAt: Time("2021-08-26T18:08:21.517447Z")
  }
}

I tried running the code again and it came up with the exact same error, including the value for "terms:" you quoted. However, I also did a search in the console for the session token I created and it found that.

Hi @PaddyShiel89 ,

Just to be clear,

Match(Index("session_by_token"),"86b962d600c3f53d41d5140de6daed654a473e670a99943d7fb301a4fc86357e")

returned data: [], but

Match(Index("session_by_token"),"997b45bb432cfbc05901e9a92ae9d1ac36637246277ac05ad915fb00b8fc9130")

returned valid data? I just want to make sure I’m not misunderstanding anything.

Cory