romandevR
Convex Community2y ago
5 replies
romandev

Lucia V3 with convex

Hi, I'm using lucia-auth to authenticate the users and I saw many repos like this and this other one
and I even found an issue referencing this (the repos are using an older version of lucia).

Actually my adapter looks like this:
  import type { DatabaseReader, DatabaseWriter } from './_generated/server';
import {
    type Adapter,
    Lucia,
    type DatabaseUser,
    type DatabaseSession,
} from 'lucia';

const convexAdapter = (db: DatabaseWriter): Adapter => { /* stuff */ }
export const auth = (db: DatabaseWriter) => new Lucia(convexAdapter(db));

but I don't know how to use it out of the convex functions context, because I need to use it in a action:

// actions/sign-up.ts
'use server';

import { api } from '@convex/_generated/api';
import { fetchMutation } from 'convex/nextjs';
import { cookies as nextCookies } from 'next/headers';

type SignUpProps = {
    email: string;
    password: string;
};

export async function signup({ email, password }: SignUpProps) {
    const { userId } = await fetchMutation(api.users.insert, {
        email,
        password,
    });

    const session = await lucia.createSession(userId, {});
    const cookies = lucia.createSessionCookie(session.id);

    nextCookies().set(cookies.name, cookies.value, cookies.attributes);
}
I don't know if this is a convex related issue or I need to open an issue in lucia-auth
GitHub
Convex database adapter for Lucia Auth. Contribute to get-convex/convex-lucia-auth development by creating an account on GitHub.
GitHub - get-convex/convex-lucia-auth: Convex database adapter for ...
GitHub
Demo showing authentication powered by Convex and Lucia - get-convex/convex-lucia-auth-demo
GitHub - get-convex/convex-lucia-auth-demo: Demo showing authentica...
Was this page helpful?