Skip to content

Commit

Permalink
Update lucia dependency to 1.0! 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarscher committed Feb 1, 2024
1 parent 855dd41 commit 147d0b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"@cloudflare/workers-wasi": "^0.0.5",
"@hono/trpc-server": "^0.1.0",
"@libsql/client": "^0.3.5",
"@lucia-auth/adapter-drizzle": "1.0.0-beta.2",
"@lucia-auth/adapter-drizzle": "1.0.0",
"@trpc/server": "^10.43.2",
"arctic": "0.10.2",
"arctic": "1.1.3",
"drizzle-orm": "^0.29.0",
"drizzle-valibot": "beta",
"hono": "^3.9.2",
"lucia": "3.0.0-beta.12",
"lucia": "3.0.1",
"miniflare": "3.20231025.1",
"oslo": "0.25.0",
"oslo": "1.0.3",
"superjson": "1.13.3",
"ts-pattern": "^5.0.5",
"valibot": "^0.20.1"
Expand Down
22 changes: 9 additions & 13 deletions packages/api/src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Adapter, DatabaseSessionAttributes, DatabaseUserAttributes, Lucia, TimeSpan } from 'lucia'
import { Adapter, Lucia, TimeSpan } from 'lucia'
import { DrizzleSQLiteAdapter } from '@lucia-auth/adapter-drizzle'
import { SessionTable, UserTable } from '../db/schema'
import { DB } from '../db/client'
Expand All @@ -22,14 +22,8 @@ export const createAuth = (db: DB, appUrl: string) => {
// @ts-ignore Expect type errors because this is D1 and not SQLite... but it works
const adapter = new DrizzleSQLiteAdapter(db, SessionTable, UserTable)
// cast probably only needed until adapter-drizzle is updated
return new Lucia(adapter as Adapter, {
...getAuthOptions(appUrl),
})
}

export const getAuthOptions = (appUrl: string) => {
const env = !appUrl || appUrl.startsWith('http:') ? 'DEV' : 'PROD'
return {
return new Lucia(adapter as Adapter, {
getUserAttributes: (data: DatabaseUserAttributes) => {
return {
email: data.email || '',
Expand All @@ -54,15 +48,17 @@ export const getAuthOptions = (appUrl: string) => {
// experimental: {
// debugMode: true,
// },
}
})
}

declare module 'lucia' {
interface Register {
Lucia: ReturnType<typeof createAuth>
DatabaseSessionAttributes: DatabaseSessionAttributes
DatabaseUserAttributes: DatabaseUserAttributes
}
interface DatabaseSessionAttributes {}
interface DatabaseUserAttributes {
email: string | null
}
}
interface DatabaseSessionAttributes {}
interface DatabaseUserAttributes {
email: string | null
}
2 changes: 1 addition & 1 deletion packages/api/src/utils/id.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateRandomString, alphabet } from 'oslo/random'
import { generateRandomString, alphabet } from 'oslo/crypto'

export const idAlphabet = alphabet('a-z', '0-9')
export const codeAlphabet = '0123456789'
Expand Down

0 comments on commit 147d0b4

Please sign in to comment.