|
1 |
| -import { eq } from 'drizzle-orm' |
2 |
| -import { merge } from 'es-toolkit' |
3 | 1 | import type { Middleware } from 'waku/config'
|
4 |
| -import { defaultPreference } from '../../constants/preference.ts' |
5 |
| -import { userPreferenceTable } from '../../databases/library/schema.ts' |
| 2 | +import type { defaultPreference } from '../../constants/preference.ts' |
| 3 | +import { getPreference } from '../../controllers/get-preference.ts' |
6 | 4 | import { createDrizzle } from '../../utils/drizzle.ts'
|
7 | 5 | import { createStorage } from '../../utils/storage.ts'
|
8 | 6 | import { createSupabase } from '../../utils/supabase.ts'
|
@@ -33,22 +31,18 @@ export default (function globalsMiddleware() {
|
33 | 31 | // const { data } = await ctx.data.supabase.auth.getUser()
|
34 | 32 | // const currentUser = data?.user
|
35 | 33 | const currentUser = { id: '567a53eb-c109-4142-8700-00f58db9853f' }
|
36 |
| - const customPreference = await db.library |
37 |
| - .select() |
38 |
| - .from(userPreferenceTable) |
39 |
| - .where(eq(userPreferenceTable.user_id, currentUser.id)) |
40 |
| - const preference = merge(defaultPreference, customPreference) |
41 | 34 |
|
42 | 35 | function redirect(location: string, status?: number) {
|
43 | 36 | ctx.res.status = status ?? 302
|
44 | 37 | ctx.res.headers ??= {}
|
45 | 38 | ctx.res.headers.location = location
|
46 | 39 | }
|
47 | 40 |
|
48 |
| - const contextData: ContextData = { currentUser, db, preference, redirect, storage, supabase } |
| 41 | + const contextData: Omit<ContextData, 'preference'> = { currentUser, db, redirect, storage, supabase } |
49 | 42 |
|
50 | 43 | Object.assign(ctx.data, contextData)
|
51 |
| - |
| 44 | + const preference = await getPreference() |
| 45 | + Object.assign(ctx.data, { preference }) |
52 | 46 | await next()
|
53 | 47 | }
|
54 | 48 | } as Middleware)
|
0 commit comments