Files
chad/server/auth/lucia.ts
Opti1337 a26343e99d
Some checks failed
Deploy / deploy (push) Has been cancelled
session livekit token
2026-09-05 14:48:36 +06:00

48 lines
1013 B
TypeScript

import { PrismaAdapter } from '@lucia-auth/adapter-prisma'
import { Lucia, TimeSpan } from 'lucia'
import prisma from '../prisma/client.ts'
declare module 'lucia' {
interface Register {
Lucia: typeof auth
UserId: string
DatabaseUserAttributes: DatabaseUserAttributes
DatabaseSessionAttributes: DatabaseSessionAttributes
}
}
interface DatabaseUserAttributes {
id: string
displayName: string
username: string
}
interface DatabaseSessionAttributes {
livekitToken: string | null
}
export const SESSION_EXPIRES_IN = new TimeSpan(30, 'd')
export const auth = new Lucia(new PrismaAdapter(prisma.session, prisma.user), {
sessionExpiresIn: SESSION_EXPIRES_IN,
sessionCookie: {
attributes: {
sameSite: 'none',
},
},
getUserAttributes: ({ id, displayName, username }) => {
return {
id,
displayName,
username,
}
},
getSessionAttributes: ({ livekitToken }) => {
return {
livekitToken,
}
},
})
export type Auth = typeof auth