Add member accounts, follow-based leaderboard, and dedicated Postgres
Members register via email+password (scrypt) or Google OAuth — same signed-cookie + scrypt pattern as LokiLab (lib/auth.ts, member-password.ts, member-auth.ts, google-oauth.ts), own AUTH_SECRET and own OAuth client, own dedicated Postgres database (lokiloto-db on Coolify), fully isolated from LokiLab's own DB and auth. Leaderboard tracks who follows Loki's picks most accurately — members star a pick from the results panel (FollowButton), resolution reuses LokiLab's own lastDraw.won, no money or pooled play involved anywhere. Leaderboard page renders a horizontal bar chart (recharts) plus a ranked list. Profile page: public nickname (required to appear on the leaderboard), list of followed picks. Header now carries nav + a user menu (avatar dropdown when signed in, "Connexion" button otherwise). Dockerfile runs prisma migrate deploy at container start via docker-entrypoint.sh, same pattern as LokiLab. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
fc69d4a668
commit
c3a0a7b765
@@ -0,0 +1,41 @@
|
||||
import 'server-only'
|
||||
import { cookies } from 'next/headers'
|
||||
import { createSessionToken, verifySessionToken, MEMBER_SESSION_COOKIE, SESSION_MAX_AGE } from './auth'
|
||||
import { prisma } from './db'
|
||||
|
||||
export async function createMemberSession(userId: string): Promise<void> {
|
||||
const token = await createSessionToken(userId)
|
||||
const jar = await cookies()
|
||||
jar.set(MEMBER_SESSION_COOKIE, token, {
|
||||
httpOnly: true,
|
||||
sameSite: 'lax',
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
maxAge: SESSION_MAX_AGE,
|
||||
path: '/',
|
||||
})
|
||||
}
|
||||
|
||||
export async function destroyMemberSession(): Promise<void> {
|
||||
const jar = await cookies()
|
||||
jar.delete(MEMBER_SESSION_COOKIE)
|
||||
}
|
||||
|
||||
export interface CurrentMember {
|
||||
id: string
|
||||
email: string
|
||||
name: string
|
||||
avatarUrl: string | null
|
||||
publicNickname: string | null
|
||||
favoriteCountry: string
|
||||
}
|
||||
|
||||
export async function getCurrentMember(): Promise<CurrentMember | null> {
|
||||
const jar = await cookies()
|
||||
const session = await verifySessionToken(jar.get(MEMBER_SESSION_COOKIE)?.value)
|
||||
if (!session) return null
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: session.sub },
|
||||
select: { id: true, email: true, name: true, avatarUrl: true, publicNickname: true, favoriteCountry: true },
|
||||
})
|
||||
return user
|
||||
}
|
||||
Reference in New Issue
Block a user