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:
Nazim Kri
2026-10-30 09:02:26 -04:00
co-authored by Claude Sonnet 5
parent fc69d4a668
commit c3a0a7b765
36 changed files with 2419 additions and 27 deletions
+42
View File
@@ -0,0 +1,42 @@
import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
import { exchangeGoogleCode } from '@/lib/google-oauth'
import { createMemberSession } from '@/lib/member-auth'
import { prisma } from '@/lib/db'
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://lotoloki.top'
function safeNext(raw: string): string {
return raw.startsWith('/') && !raw.startsWith('//') ? raw : '/'
}
export async function GET(req: Request) {
const url = new URL(req.url)
const origin = SITE_URL
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const jar = await cookies()
const savedState = jar.get('g_state')?.value
if (!code || !state || state !== savedState) {
return NextResponse.redirect(`${origin}/connexion?error=oauth_state`)
}
const next = safeNext(decodeURIComponent(state.split('.')[1] ?? '/'))
const profile = await exchangeGoogleCode(code)
if (!profile?.email) {
return NextResponse.redirect(`${origin}/connexion?error=oauth_failed`)
}
const email = profile.email.toLowerCase()
const user = await prisma.user.upsert({
where: { googleSub: profile.sub },
update: { email, name: profile.name || email.split('@')[0], avatarUrl: profile.picture ?? null },
create: { email, name: profile.name || email.split('@')[0], avatarUrl: profile.picture ?? null, googleSub: profile.sub },
})
await createMemberSession(user.id)
const res = NextResponse.redirect(`${origin}${next}`)
res.cookies.delete('g_state')
return res
}
+26
View File
@@ -0,0 +1,26 @@
import { NextResponse } from 'next/server'
import { getGoogleAuthUrl, googleEnabled } from '@/lib/google-oauth'
function safeNext(raw: string | null): string {
return raw && raw.startsWith('/') && !raw.startsWith('//') ? raw : '/'
}
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://lotoloki.top'
export async function GET(req: Request) {
const url = new URL(req.url)
if (!googleEnabled) {
return NextResponse.redirect(`${SITE_URL}/connexion?error=google_not_configured`)
}
const next = safeNext(url.searchParams.get('next'))
const state = `${crypto.randomUUID()}.${encodeURIComponent(next)}`
const res = NextResponse.redirect(getGoogleAuthUrl(state))
res.cookies.set('g_state', state, {
httpOnly: true,
sameSite: 'lax',
secure: process.env.NODE_ENV === 'production',
maxAge: 600,
path: '/',
})
return res
}
+9
View File
@@ -0,0 +1,9 @@
import { NextResponse } from 'next/server'
import { destroyMemberSession } from '@/lib/member-auth'
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://lotoloki.top'
export async function POST() {
await destroyMemberSession()
return NextResponse.redirect(`${SITE_URL}/`, { status: 303 })
}