lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
MIT License
9.19k stars 467 forks source link

[Bug]: await is not defined #1676

Open osama-mhmd opened 1 month ago

osama-mhmd commented 1 month ago

Package

lucia

Describe the bug

In the docs, it's written that you should write in the adpter the following code:

await mongoose.connect();

and this throws an error Error: await is not defined.

I tried to make a function called getAdapter() like this:

async function getAdpater() {
  await mongoose.connect(uri);

  const User = mongoose.model("User", userSchema);

  const Session = mongoose.model("Session", sessionSchema);

  return new MongodbAdapter(
    mongoose.connection.collection("sessions"),
    mongoose.connection.collection("users")
  );
}

export { getAdpater };

and in lucia.ts file:

export const lucia = new Lucia(await getAdpater(), {
  sessionCookie: {
    attributes: {
      // set to `true` when using HTTPS
      secure: process.env.NODE_ENV === "production",
    },
  },
});

but this don't work, so I recommend making lucia gets a function that returns an adapter or something like that (new Lucia(async () => await getAdapter())), i don't know actually...

btw I'm using nextjs and server actions