#Lucia not found

1 messages · Page 1 of 1 (latest)

hollow slate
#

When I try to import getAuth from lucia, my project cannot find it. When I call npm i lucia, it appears to be already installed. What else do I have to do to prepare myself for custom authorization flow?

pine voidBOT
#

Hi @hollow slate. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The getAuth function is not a part of the Lucia library, but a function you define in your project to interact with Lucia from your server queries and mutations. This function will instantiate Lucia with your Convex adapter. Here is the code for the getAuth function:

// lucia.ts
import { lucia } from "lucia";
import { DatabaseWriter } from "./_generated/server";

export function getAuth(db: DatabaseWriter) {
  return lucia({
    adapter: convexAdapter(db),
    env: (process.env.LUCIA_ENVIRONMENT as "PROD" | undefined) ?? "DEV",
    getUserAttributes(user: UserSchema) {
      return {
        _id: user._id,
        _creationTime: user._creationTime,
        email: user.email,
      };
    },
  });
}

You can call this function from any query or mutation, passing in ctx.db. convexAdapter is the actual database adapter implementation. You can check out its source on Github (https://github.com/get-convex/convex-lucia-auth-demo/blob/main/convex/lucia.ts).

If you want to start a new project with a template that includes authentication based on Lucia, you can run npm create convex@latest -- -t nextjs-lucia-shadcn. This will use the convex-lucia-auth (https://www.npmjs.com/package/@convex-dev/convex-lucia-auth) NPM library.

For more information, you can refer to the source (https://stack.convex.dev/convex-with-lucia#step-2-configure-lucia).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@hollow slate kapa.ai is still learning and improving, please let us know how it did by reacting below

hollow slate
#

@pine void When I add this script, { lucia } cannot be found.

pine voidBOT
#

Let me check the knowledge base for you. One moment! :books:

#

It seems like there might be a misunderstanding. The lucia in the import statement import { lucia } from "lucia"; is not a function or object provided by the Lucia library. Instead, it's a function that you need to define in your project.

The lucia function is used to create an instance of Lucia with the specified adapter and environment. Here's an example of how you might define it:

function lucia({ adapter, env, getUserAttributes }) {
  // Your implementation here
}

In the context of the getAuth function, lucia is called with an object that includes the Convex adapter, the environment, and a getUserAttributes function.

If you're following the guide from the source (https://stack.convex.dev/convex-with-lucia#step-2-configure-lucia), make sure you've correctly set up your project and that you've defined all the necessary functions and variables. If you're still having trouble, it might be helpful to check out the template repo (https://github.com/get-convex/convex-lucia-auth-demo) for a complete example.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: