romandev
romandev
CCConvex Community
Created by romandev on 3/26/2024 in #support-community
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));
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);
}
// 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
6 replies
CCConvex Community
Created by romandev on 3/26/2024 in #support-community
Conflict with oslo package
I'm using convex with lucia-auth and lucia-auth recommends to use oslo/password to hash them. My code is:
'use node';

import { generateId } from 'lucia';
import { v } from 'convex/values';
import { mutation } from './_generated/server';
import { auth } from './auth';
import { Argon2id } from 'oslo/password';

export const insert = mutation({
args: { email: v.string(), password: v.string() },
handler: async (ctx, { email, password }) => {
const lucia = auth(ctx.db);
const userId = generateId(15);
console.log({ userId, email, password });
const hashedPassword = await new Argon2id().hash(password);
await ctx.db.insert('users', {
id: userId,
email,
password: hashedPassword,
});
const sessionId = await lucia.createSession(userId, {});
return sessionId;
},
});
'use node';

import { generateId } from 'lucia';
import { v } from 'convex/values';
import { mutation } from './_generated/server';
import { auth } from './auth';
import { Argon2id } from 'oslo/password';

export const insert = mutation({
args: { email: v.string(), password: v.string() },
handler: async (ctx, { email, password }) => {
const lucia = auth(ctx.db);
const userId = generateId(15);
console.log({ userId, email, password });
const hashedPassword = await new Argon2id().hash(password);
await ctx.db.insert('users', {
id: userId,
email,
password: hashedPassword,
});
const sessionId = await lucia.createSession(userId, {});
return sessionId;
},
});
But for some reason, the convex dev command returns this error:
✘ [ERROR] No loader is configured for ".node" files: node_modules/.pnpm/@node-rs+argon2-android-arm-eabi@1.7.0/node_modules/@node-rs/argon2-android-arm-eabi/argon2.android-arm-eabi.node

node_modules/.pnpm/@node-rs+argon2@1.7.0/node_modules/@node-rs/argon2/index.js:84:36:
84 │ nativeBinding = require('@node-rs/argon2-android-arm-eabi')
✘ [ERROR] No loader is configured for ".node" files: node_modules/.pnpm/@node-rs+argon2-android-arm-eabi@1.7.0/node_modules/@node-rs/argon2-android-arm-eabi/argon2.android-arm-eabi.node

node_modules/.pnpm/@node-rs+argon2@1.7.0/node_modules/@node-rs/argon2/index.js:84:36:
84 │ nativeBinding = require('@node-rs/argon2-android-arm-eabi')
4 replies