- Rename directory keep-notes -> memento-note with all code references - Prisma: SQLite -> PostgreSQL (both app and MCP server schemas) - Sync MCP schema with main app (add missing fields, relations, indexes) - Delete 17 SQLite migrations (clean slate for PostgreSQL) - Remove SQLite dependencies (@libsql/client, better-sqlite3, etc.) - Fix MCP server: hardcoded Windows DB paths -> DATABASE_URL env var - Fix MCP server: .dockerignore excluded index-sse.js (SSE mode broken) - MCP Dockerfile: node:20 -> node:22 - Docker Compose: add postgres service, remove SQLite volume - Generate favicon.ico, icon-192.png, icon-512.png, apple-icon.png - Update layout.tsx icons and manifest.json for PNG icons - Update all .env files for PostgreSQL - Rewrite README.md with updated sections - Remove mcp-server/node_modules and prisma/client-generated from git tracking Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
84 lines
1.8 KiB
TypeScript
84 lines
1.8 KiB
TypeScript
'use server'
|
|
|
|
import { auth } from '@/auth'
|
|
import { prisma } from '@/lib/prisma'
|
|
import { revalidatePath, revalidateTag } from 'next/cache'
|
|
|
|
export type UserSettingsData = {
|
|
theme?: 'light' | 'dark' | 'auto' | 'sepia' | 'midnight' | 'blue'
|
|
}
|
|
|
|
/**
|
|
* Update user settings (theme, etc.)
|
|
*/
|
|
export async function updateUserSettings(settings: UserSettingsData) {
|
|
|
|
const session = await auth()
|
|
|
|
if (!session?.user?.id) {
|
|
console.error('[updateUserSettings] Unauthorized')
|
|
throw new Error('Unauthorized')
|
|
}
|
|
|
|
try {
|
|
const result = await prisma.user.update({
|
|
where: { id: session.user.id },
|
|
data: settings
|
|
})
|
|
|
|
|
|
revalidatePath('/', 'layout')
|
|
revalidateTag('user-settings')
|
|
|
|
return { success: true }
|
|
} catch (error) {
|
|
console.error('Error updating user settings:', error)
|
|
throw new Error('Failed to update user settings')
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get user settings for current user (Cached)
|
|
*/
|
|
import { unstable_cache } from 'next/cache'
|
|
|
|
// Internal cached function
|
|
const getCachedUserSettings = unstable_cache(
|
|
async (userId: string) => {
|
|
try {
|
|
const user = await prisma.user.findUnique({
|
|
where: { id: userId },
|
|
select: { theme: true }
|
|
})
|
|
|
|
return {
|
|
theme: (user?.theme || 'light') as 'light' | 'dark' | 'auto' | 'sepia' | 'midnight' | 'blue'
|
|
}
|
|
} catch (error) {
|
|
console.error('Error getting user settings:', error)
|
|
return {
|
|
theme: 'light' as const
|
|
}
|
|
}
|
|
},
|
|
['user-settings'],
|
|
{ tags: ['user-settings'] }
|
|
)
|
|
|
|
export async function getUserSettings(userId?: string) {
|
|
let id = userId
|
|
|
|
if (!id) {
|
|
const session = await auth()
|
|
id = session?.user?.id
|
|
}
|
|
|
|
if (!id) {
|
|
return {
|
|
theme: 'light' as const
|
|
}
|
|
}
|
|
|
|
return getCachedUserSettings(id)
|
|
}
|