Visual theme and sign-in with Authentik #19

Merged
miko merged 4 commits from development into master 2026-11-01 17:44:47 +01:00
Owner

Closes #16
Closes #4

Summary

Theme (#16, ADR-0010): semantic Tailwind tokens with light/dark, a Light/Dark/System switch stored in a cookie, logo and icons, Inter, Lucide, and tiles for categories and guides.

Sign-in (#4, ADR-0009): Auth.js with Authentik and JWT sessions. The role is derived from the groups claim at each sign-in, and permission checks read it from the database.

sign-in (Authentik OIDC)
  jwt callback
    roleFromGroups(groups claim, KATABA_ADMIN_GROUP / KATABA_AUTHOR_GROUP)
    upsert User (authSubject, name, email, role, lastLoginAt)
    token.userId = User.id
request
  getCurrentUser()
    auth() → userId
    db.user → role read from database, not token
 src/
+├── auth/
+│   ├── auth.ts          # Auth.js config, upsert on sign-in
+│   ├── role.ts          # groups claim → viewer / author / admin
+│   └── currentUser.ts   # current user, role from database
+├── db.ts                # Prisma client (MariaDB adapter)
 ├── components/
+│   ├── Account.tsx      # sign in / name + sign out
 │   └── Titlebar.tsx     # + <Suspense><Account/></Suspense>
+prisma/migrations/       # User table, Role enum

Evidence

  • Group → role: 6 unit tests in src/auth/role.test.ts. Admin wins over author; a user in neither group is a viewer. A missing or malformed claim and an unset group variable both grant nothing.
  • Before: after a successful Authentik login, saving the user failed with error parsing connection string, format must be 'mariadb://…'
    After: the sign-in round trip against Authentik completes. The User row is saved with the role derived from groups, and the name and Sign out show in the Titlebar.
  • tsc, eslint, 19/19 tests pass. next build: / remains a partial prerender, with the account area streamed in.

Merge Danger

Door: two-way, apart from the migration

The migration creates the User table. Rolling back the code is cheap, but the table and the users in it remain.

Blast Radius: deployment

The deployment needs AUTH_SECRET, AUTH_AUTHENTIK_*, KATABA_*_GROUP, and prisma migrate deploy. The Authentik app must allow <origin>/api/auth/callback/authentik as a redirect URI. Open follow-ups:

  • Session lifetime stays at the Auth.js default until it becomes a setting (#5).
  • "Sign in" and "Sign out" are hard-coded until Lingui (#3).

🤖 Generated with Claude Code

Closes #16 Closes #4 ## Summary **Theme (#16, ADR-0010):** semantic Tailwind tokens with light/dark, a Light/Dark/System switch stored in a cookie, logo and icons, Inter, Lucide, and tiles for categories and guides. **Sign-in (#4, ADR-0009):** Auth.js with Authentik and JWT sessions. The role is derived from the groups claim at each sign-in, and permission checks read it from the database. ```text sign-in (Authentik OIDC) jwt callback roleFromGroups(groups claim, KATABA_ADMIN_GROUP / KATABA_AUTHOR_GROUP) upsert User (authSubject, name, email, role, lastLoginAt) token.userId = User.id request getCurrentUser() auth() → userId db.user → role read from database, not token ``` ```diff src/ +├── auth/ +│ ├── auth.ts # Auth.js config, upsert on sign-in +│ ├── role.ts # groups claim → viewer / author / admin +│ └── currentUser.ts # current user, role from database +├── db.ts # Prisma client (MariaDB adapter) ├── components/ +│ ├── Account.tsx # sign in / name + sign out │ └── Titlebar.tsx # + <Suspense><Account/></Suspense> +prisma/migrations/ # User table, Role enum ``` ## Evidence - **Group → role:** 6 unit tests in `src/auth/role.test.ts`. Admin wins over author; a user in neither group is a viewer. A missing or malformed claim and an unset group variable both grant nothing. - **Before:** after a successful Authentik login, saving the user failed with `error parsing connection string, format must be 'mariadb://…'` **After:** the sign-in round trip against Authentik completes. The User row is saved with the role derived from groups, and the name and Sign out show in the Titlebar. - `tsc`, `eslint`, 19/19 tests pass. `next build`: `/` remains a partial prerender, with the account area streamed in. ## Merge Danger **Door:** two-way, apart from the migration The migration creates the `User` table. Rolling back the code is cheap, but the table and the users in it remain. **Blast Radius:** deployment The deployment needs `AUTH_SECRET`, `AUTH_AUTHENTIK_*`, `KATABA_*_GROUP`, and `prisma migrate deploy`. The Authentik app must allow `<origin>/api/auth/callback/authentik` as a redirect URI. Open follow-ups: - Session lifetime stays at the Auth.js default until it becomes a setting (#5). - "Sign in" and "Sign out" are hard-coded until Lingui (#3). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Semantic Tailwind 4 tokens with light-dark(); Tailwind default colours removed
- Palette, curated accent and tile colours as approved on the review page
- Light/Dark/System switch stored in a cookie, applied by an inline head script
- Logo A3 (ring + dot), favicon and generated apple icon; Inter via next/font
- Lucide icons; Tile component for categories and guides with colour fallback
- src/theme: pure helpers for theme preference, palette, tile and accent colours

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Auth.js v5 with the Authentik provider and JWT sessions
- Prisma User model (authSubject unique, role enum) with initial migration;
  upserted on every sign-in
- Role derived from the groups claim via KATABA_ADMIN_GROUP /
  KATABA_AUTHOR_GROUP; neither group, or a missing claim, means viewer
- getCurrentUser() reads the role from the database, not the token
- Sign-in / sign-out and the current user's name in the Titlebar
- Alias smoke test now imports Logo: Titlebar pulls in server-only auth code

Session lifetime stays at the Auth.js default until settings exist (ADR-0009).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Prisma CLI needs mysql://, the MariaDB driver only accepts mariadb://;
sign-in failed with a connection-string parse error when upserting the user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
miko merged commit 2b47e47296 into master 2026-11-01 17:44:47 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MassiveDynamic/kataba!19
No description provided.