Migrate shared UI and backend components
Lint / Lint (push) Failing after 7s
Tests / Go backend (push) Failing after 6s
Tests / Dashboard checks (push) Failing after 4s
Docker / Docker Build & Push (push) Failing after 10s

This commit is contained in:
Gabriel20xx committed 2026-08-04 17:05:37 +02:00
1 parent 64d22d0aac
commit ac08be0248
16 files changed
+235 -394

No files matched your search

+2
View File
@@ -30,6 +30,8 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v7 uses: actions/checkout@v7
with:
submodules: recursive
# Multi-arch (arm64) is only built and published from main; other branches and PRs # Multi-arch (arm64) is only built and published from main; other branches and PRs
# only need an amd64 build to validate they compile, which needs no emulation. # only need an amd64 build to validate they compile, which needs no emulation.
+2
View File
@@ -31,6 +31,8 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
+4
View File
@@ -31,6 +31,8 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
@@ -53,6 +55,8 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Node.js - name: Set up Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
+3
View File
@@ -0,0 +1,3 @@
[submodule "SharedCode"]
path = SharedCode
url = https://repos.gfranz.ch/Gabriel20xx/SharedCode.git
Submodule
+1
Submodule SharedCode added at c95865dbe2.
+5 -5
View File
@@ -11,7 +11,7 @@ import (
"strings" "strings"
"time" "time"
"golang.org/x/crypto/bcrypt" sharedauth "repos.gfranz.ch/Gabriel20xx/SharedCode/backend/auth"
) )
const ( const (
@@ -238,7 +238,7 @@ func (a *AuthService) handleSetup(w http.ResponseWriter, r *http.Request) {
return return
} }
hash, err := bcrypt.GenerateFromPassword([]byte(request.Password), bcrypt.DefaultCost) hash, err := sharedauth.HashPassword(request.Password)
if err != nil { if err != nil {
writeJSONError(w, http.StatusInternalServerError, "Internal server error") writeJSONError(w, http.StatusInternalServerError, "Internal server error")
return return
@@ -283,7 +283,7 @@ func (a *AuthService) handleLogin(w http.ResponseWriter, r *http.Request) {
writeJSONError(w, http.StatusInternalServerError, "Internal server error") writeJSONError(w, http.StatusInternalServerError, "Internal server error")
return return
} }
if user == nil || bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(request.Password)) != nil { if user == nil || !sharedauth.VerifyPassword(user.PasswordHash, request.Password) {
writeJSONError(w, http.StatusUnauthorized, errInvalidCredentials.Error()) writeJSONError(w, http.StatusUnauthorized, errInvalidCredentials.Error())
return return
} }
@@ -318,7 +318,7 @@ func (a *AuthService) handleUpdateCredentials(w http.ResponseWriter, r *http.Req
writeJSONError(w, http.StatusBadRequest, "Invalid JSON body") writeJSONError(w, http.StatusBadRequest, "Invalid JSON body")
return return
} }
if request.CurrentPassword != nil && *request.CurrentPassword != "" && bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(*request.CurrentPassword)) != nil { if request.CurrentPassword != nil && *request.CurrentPassword != "" && !sharedauth.VerifyPassword(user.PasswordHash, *request.CurrentPassword) {
writeJSONError(w, http.StatusBadRequest, errCurrentPasswordBad.Error()) writeJSONError(w, http.StatusBadRequest, errCurrentPasswordBad.Error())
return return
} }
@@ -347,7 +347,7 @@ func (a *AuthService) handleUpdateCredentials(w http.ResponseWriter, r *http.Req
writeJSONError(w, http.StatusBadRequest, err.Error()) writeJSONError(w, http.StatusBadRequest, err.Error())
return return
} }
hash, err := bcrypt.GenerateFromPassword([]byte(*request.NewPassword), bcrypt.DefaultCost) hash, err := sharedauth.HashPassword(*request.NewPassword)
if err != nil { if err != nil {
writeJSONError(w, http.StatusInternalServerError, "Internal server error") writeJSONError(w, http.StatusInternalServerError, "Internal server error")
return return
+6 -22
View File
@@ -7,8 +7,9 @@ import (
"time" "time"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
sharedpostgres "repos.gfranz.ch/Gabriel20xx/SharedCode/backend/postgres"
) )
// DB owns the PostgreSQL pool. The schema deliberately uses the same physical // DB owns the PostgreSQL pool. The schema deliberately uses the same physical
@@ -19,13 +20,9 @@ type DB struct {
} }
func connectDB(ctx context.Context, connectionString string) (*DB, error) { func connectDB(ctx context.Context, connectionString string) (*DB, error) {
pool, err := pgxpool.New(ctx, connectionString) pool, err := sharedpostgres.Open(ctx, sharedpostgres.DefaultConfig(connectionString))
if err != nil { if err != nil {
return nil, fmt.Errorf("create pool: %w", err) return nil, err
}
if err := pool.Ping(ctx); err != nil {
pool.Close()
return nil, fmt.Errorf("ping database: %w", err)
} }
return &DB{pool: pool}, nil return &DB{pool: pool}, nil
} }
@@ -35,19 +32,7 @@ func (d *DB) close() {
} }
func (d *DB) withTx(ctx context.Context, fn func(pgx.Tx) error) error { func (d *DB) withTx(ctx context.Context, fn func(pgx.Tx) error) error {
tx, err := d.pool.Begin(ctx) return sharedpostgres.WithTx(ctx, d.pool, fn)
if err != nil {
return fmt.Errorf("begin transaction: %w", err)
}
defer tx.Rollback(ctx) // harmless after a successful commit
if err := fn(tx); err != nil {
return err
}
if err := tx.Commit(ctx); err != nil {
return fmt.Errorf("commit transaction: %w", err)
}
return nil
} }
// initSchema is idempotent so an existing CollabTable PostgreSQL database can // initSchema is idempotent so an existing CollabTable PostgreSQL database can
@@ -211,8 +196,7 @@ func (d *DB) createUser(ctx context.Context, username, email, passwordHash strin
RETURNING id, username, email RETURNING id, username, email
`, username, email, passwordHash).Scan(&user.ID, &user.Username, &user.Email) `, username, email, passwordHash).Scan(&user.ID, &user.Username, &user.Email)
if err != nil { if err != nil {
var pgErr *pgconn.PgError if sharedpostgres.IsUniqueViolation(err) {
if errors.As(err, &pgErr) && pgErr.Code == "23505" {
return nil, ErrSingletonUserExists return nil, ErrSingletonUserExists
} }
return nil, fmt.Errorf("create user: %w", err) return nil, fmt.Errorf("create user: %w", err)
+5 -1
View File
@@ -5,13 +5,17 @@ go 1.26.5
require ( require (
github.com/jackc/pgx/v5 v5.10.0 github.com/jackc/pgx/v5 v5.10.0
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
golang.org/x/crypto v0.54.0
) )
require golang.org/x/crypto v0.54.0 // indirect
require ( require (
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect
golang.org/x/sync v0.22.0 // indirect golang.org/x/sync v0.22.0 // indirect
golang.org/x/text v0.40.0 // indirect golang.org/x/text v0.40.0 // indirect
repos.gfranz.ch/Gabriel20xx/SharedCode/backend v0.0.0
) )
replace repos.gfranz.ch/Gabriel20xx/SharedCode/backend => ../SharedCode/backend
+152 -1
View File
@@ -13,7 +13,8 @@
"bits-ui": "latest", "bits-ui": "latest",
"class-variance-authority": "latest", "class-variance-authority": "latest",
"clsx": "latest", "clsx": "latest",
"tailwind-merge": "latest" "tailwind-merge": "latest",
"@gabriel20xx/shared-code": "git+https://repos.gfranz.ch/Gabriel20xx/SharedCode.git#c95865d"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "latest", "@eslint/js": "latest",
@@ -3419,6 +3420,156 @@
"resolved": "https://registry.npmjs.org/zimmerframe/-/zimmerframe-1.1.4.tgz", "resolved": "https://registry.npmjs.org/zimmerframe/-/zimmerframe-1.1.4.tgz",
"integrity": "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==", "integrity": "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==",
"license": "MIT" "license": "MIT"
},
"node_modules/@gabriel20xx/shared-code": {
"version": "0.1.0",
"resolved": "git+https://repos.gfranz.ch/Gabriel20xx/SharedCode.git#c95865dbe2be79fce08035ecd6d0b324eea9116c",
"license": "MIT",
"workspaces": [
"packages/*"
],
"dependencies": {
"pg": "^8.17.2"
}
},
"node_modules/pg": {
"version": "8.22.0",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.22.0.tgz",
"integrity": "sha512-8wih1vVIBMxoUM2oB4soJsD9tDnDpLv4OXBJ+EJzFsvycD+lfyIreC2gGHq78f8jbLLt+bvlPTFdFZfJkOuzAA==",
"license": "MIT",
"dependencies": {
"pg-connection-string": "^2.14.0",
"pg-pool": "^3.14.0",
"pg-protocol": "^1.15.0",
"pg-types": "2.2.0",
"pgpass": "1.0.5"
},
"engines": {
"node": ">= 16.0.0"
},
"optionalDependencies": {
"pg-cloudflare": "^1.4.0"
},
"peerDependencies": {
"pg-native": ">=3.0.1"
},
"peerDependenciesMeta": {
"pg-native": {
"optional": true
}
}
},
"node_modules/pg-connection-string": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.14.0.tgz",
"integrity": "sha512-XwWDGcLRGCXAR8F/AM5bG7Q+A3Wm2s6QeEjlOKZLlH3UYcguiqCWKyWXVag5TLTIjR7oOJUY8kcADaZgWPyLeg==",
"license": "MIT"
},
"node_modules/pg-pool": {
"version": "3.14.0",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.14.0.tgz",
"integrity": "sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==",
"license": "MIT",
"peerDependencies": {
"pg": ">=8.0"
}
},
"node_modules/pg-protocol": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.15.0.tgz",
"integrity": "sha512-cq9sECI5s0+uPUXjbz8ioyPJni6RzsRib0US67i5IoTZKw8fNeYlVE7u8F4dG7vEJJtc5wdD1K189lCCUwqWTQ==",
"license": "MIT"
},
"node_modules/pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"license": "MIT",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/pgpass": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
"license": "MIT",
"dependencies": {
"split2": "^4.1.0"
}
},
"node_modules/pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
"license": "ISC",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
"license": "MIT",
"engines": {
"node": ">=4"
}
},
"node_modules/postgres-bytea": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz",
"integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"license": "MIT",
"dependencies": {
"xtend": "^4.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/split2": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
"license": "ISC",
"engines": {
"node": ">= 10.x"
}
},
"node_modules/xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"license": "MIT",
"engines": {
"node": ">=0.4"
}
} }
} }
} }
+1
View File
@@ -30,6 +30,7 @@
"vite": "latest" "vite": "latest"
}, },
"dependencies": { "dependencies": {
"@gabriel20xx/shared-code": "git+https://repos.gfranz.ch/Gabriel20xx/SharedCode.git#c95865d",
"@lucide/svelte": "latest", "@lucide/svelte": "latest",
"@tanstack/svelte-query": "latest", "@tanstack/svelte-query": "latest",
"bits-ui": "latest", "bits-ui": "latest",
-126
View File
@@ -1,126 +0,0 @@
<script module>
import { Info, LayoutDashboard } from '@lucide/svelte';
const navItems = [
{ to: '/', end: true, icon: LayoutDashboard, label: 'Overview' },
{ to: '/about', icon: Info, label: 'About' },
];
function isActive(pathname, target, end) {
if (end) return pathname === target;
return pathname === target || pathname.startsWith(`${target}/`);
}
</script>
<script>
import { page } from '$app/state';
import { resolve } from '$app/paths';
import { LogOut, Menu, Table2, Settings, UserRound, X } from '@lucide/svelte';
import { cn } from '$lib/utils/cn.js';
import Button from '$lib/components/ui/button.svelte';
import HealthWidget from '$lib/features/health/HealthWidget.svelte';
import SettingsDialog from '$lib/features/layout/SettingsDialog.svelte';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '$lib/components/ui/dropdown-menu';
import { useAuth } from '$lib/features/auth/auth.svelte.js';
import CredentialsDialog from '$lib/features/auth/CredentialsDialog.svelte';
const navLinkClass = (active) =>
cn(
'inline-flex shrink-0 items-center gap-2 whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium transition-colors hover:bg-surface-hover',
active && 'bg-surface-hover text-primary',
);
const auth = useAuth();
let navOpen = $state(false);
let settingsOpen = $state(false);
let credentialsOpen = $state(false);
</script>
<header class="sticky top-0 z-40 flex h-14 items-center gap-2 border-b border-border bg-bg px-3">
<a href={resolve('/')} class="flex shrink-0 items-center gap-2 pr-1 font-semibold text-fg">
<Table2 class="size-5 text-primary" />
<span>CollabTable</span>
</a>
<Button
variant="ghost"
size="icon"
class="ml-auto min-[640px]:hidden"
aria-label="Toggle navigation"
aria-expanded={navOpen}
aria-controls="primary-navigation"
onclick={() => (navOpen = !navOpen)}
>
{#if navOpen}
<X class="size-5" />
{:else}
<Menu class="size-5" />
{/if}
</Button>
<nav
id="primary-navigation"
class={cn(
'min-[640px]:flex min-[640px]:items-center min-[640px]:gap-1',
'absolute left-0 right-0 top-full flex flex-col gap-1 border-b border-border bg-bg p-2 shadow-lg min-[640px]:static min-[640px]:flex-row min-[640px]:border-b-0 min-[640px]:bg-transparent min-[640px]:p-0 min-[640px]:shadow-none',
!navOpen && 'hidden min-[640px]:flex',
)}
>
{#each navItems as item (item.to)}
{@const href = resolve(item.to)}
<a
{href}
class={cn(
navLinkClass(isActive(page.url.pathname, href, item.end)),
'w-full justify-start py-2 min-[640px]:w-auto min-[640px]:py-1.5',
)}
onclick={() => (navOpen = false)}
>
<item.icon class="size-4" />
{item.label}
</a>
{/each}
</nav>
<div class="flex shrink-0 items-center gap-1 min-[640px]:ml-auto">
<HealthWidget />
<Button variant="ghost" size="icon" aria-label="Settings" onclick={() => (settingsOpen = true)}>
<Settings class="size-5" />
</Button>
<DropdownMenu>
<DropdownMenuTrigger>
{#snippet child({ props })}
<Button variant="ghost" size="sm" class="max-[639px]:size-9 max-[639px]:p-0" aria-label="Account" {...props}>
<UserRound class="size-5" />
<span class="hidden min-[640px]:inline">{auth.status?.username ?? ''}</span>
</Button>
{/snippet}
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem onSelect={() => (credentialsOpen = true)}>
<UserRound class="size-4" />
Profile
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onSelect={() => void auth.logout()}>
<LogOut class="size-4" />
Sign out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</header>
<CredentialsDialog
bind:open={credentialsOpen}
currentUsername={auth.status?.username ?? ''}
currentEmail={auth.status?.email ?? ''}
/>
<SettingsDialog bind:open={settingsOpen} />
+10 -111
View File
@@ -1,119 +1,18 @@
<script> <script>
import { Table2 } from '@lucide/svelte'; import { AuthPage as SharedAuthPage } from '@gabriel20xx/shared-code/web-ui';
import Button from '$lib/components/ui/button.svelte';
import { useAuth } from '$lib/features/auth/auth.svelte.js'; import { useAuth } from '$lib/features/auth/auth.svelte.js';
let { setupRequired } = $props(); let { setupRequired } = $props();
const auth = useAuth(); const auth = useAuth();
let username = $state(''); const onLogin = (input) => auth.login(input.identifier, input.password);
let email = $state(''); const onSetup = (input) => auth.setup(input.username, input.email, input.password);
let identifier = $state('');
let password = $state('');
let confirmPassword = $state('');
let submitting = $state(false);
let error = $state('');
async function submit(event) {
event.preventDefault();
error = '';
if (setupRequired && password !== confirmPassword) {
error = 'Passwords do not match.';
return;
}
submitting = true;
try {
if (setupRequired) {
await auth.setup(username, email, password);
} else {
await auth.login(identifier, password);
}
} catch (submitError) {
error = submitError instanceof Error ? submitError.message : 'Request failed.';
} finally {
submitting = false;
}
}
</script> </script>
<main class="flex min-h-screen items-center justify-center bg-bg px-4 py-8"> <SharedAuthPage
<section class="w-full max-w-sm rounded-lg border border-border bg-surface p-6 shadow-sm"> brand="CollabTable"
<div class="mb-6 flex flex-col items-center gap-2 text-center"> tagline="Collaborative tables for your team"
<Table2 class="size-8 text-primary" /> {setupRequired}
<h1 class="text-xl font-semibold">CollabTable</h1> {onLogin}
<p class="text-sm text-muted-fg"> {onSetup}
{setupRequired ? 'Create the admin account for this dashboard.' : 'Sign in to view this dashboard.'} />
</p>
</div>
<form class="space-y-4" onsubmit={submit}>
{#if setupRequired}
<label for="auth-username" class="mb-1 block text-sm font-medium">Username</label>
<!-- svelte-ignore a11y_autofocus -->
<input
id="auth-username"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={username}
autocomplete="username"
required
autofocus
/>
<label for="auth-email" class="mb-1 block text-sm font-medium">Email</label>
<input
id="auth-email"
type="email"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={email}
autocomplete="email"
required
/>
{:else}
<label for="auth-identifier" class="mb-1 block text-sm font-medium">Username or email</label>
<!-- svelte-ignore a11y_autofocus -->
<input
id="auth-identifier"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={identifier}
autocomplete="username"
required
autofocus
/>
{/if}
<div>
<label for="auth-password" class="mb-1 block text-sm font-medium">Password</label>
<input
id="auth-password"
type="password"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={password}
autocomplete={setupRequired ? 'new-password' : 'current-password'}
minlength={8}
required
/>
</div>
{#if setupRequired}
<div>
<label for="auth-confirm-password" class="mb-1 block text-sm font-medium">Confirm password</label>
<input
id="auth-confirm-password"
type="password"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={confirmPassword}
autocomplete="new-password"
minlength={8}
required
/>
</div>
{/if}
{#if error}
<p class="text-sm text-danger">{error}</p>
{/if}
<Button type="submit" class="w-full" disabled={submitting}>
{submitting ? 'Working…' : setupRequired ? 'Create account' : 'Sign in'}
</Button>
</form>
</section>
</main>
@@ -1,111 +0,0 @@
<script>
import Button from '$lib/components/ui/button.svelte';
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '$lib/components/ui/dialog';
import { useAuth } from '$lib/features/auth/auth.svelte.js';
let { open = $bindable(false), currentUsername, currentEmail } = $props();
const auth = useAuth();
let username = $state('');
let email = $state('');
let newPassword = $state('');
let confirmPassword = $state('');
let error = $state('');
let saving = $state(false);
$effect(() => {
if (open) {
username = currentUsername;
email = currentEmail;
}
});
async function submit(event) {
event.preventDefault();
error = '';
if (newPassword !== confirmPassword) {
error = 'Passwords do not match.';
return;
}
saving = true;
try {
await auth.updateCredentials({
newUsername: username.trim() || undefined,
newEmail: email.trim() || undefined,
newPassword: newPassword || undefined,
});
newPassword = '';
confirmPassword = '';
open = false;
} catch (saveError) {
error = saveError instanceof Error ? saveError.message : 'Request failed.';
} finally {
saving = false;
}
}
</script>
<Dialog bind:open>
<DialogContent>
<DialogHeader>
<DialogTitle>Account</DialogTitle>
</DialogHeader>
<form class="space-y-4" onsubmit={submit}>
<p class="text-sm text-muted-fg">Changing your credentials will sign you out everywhere.</p>
<div>
<label for="credentials-username" class="mb-1 block text-sm font-medium">Username</label>
<input
id="credentials-username"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={username}
autocomplete="username"
/>
</div>
<div>
<label for="credentials-email" class="mb-1 block text-sm font-medium">Email</label>
<input
id="credentials-email"
type="email"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={email}
autocomplete="email"
required
/>
</div>
<div>
<label for="credentials-new-password" class="mb-1 block text-sm font-medium">New password</label>
<input
id="credentials-new-password"
type="password"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={newPassword}
autocomplete="new-password"
minlength={8}
placeholder="Leave blank to keep your password"
/>
</div>
<div>
<label for="credentials-confirm-password" class="mb-1 block text-sm font-medium">Confirm new password</label>
<input
id="credentials-confirm-password"
type="password"
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
bind:value={confirmPassword}
autocomplete="new-password"
minlength={8}
/>
</div>
{#if error}
<p class="text-sm text-danger">{error}</p>
{/if}
<DialogFooter>
<Button type="submit" disabled={saving}>
{saving ? 'Saving…' : 'Save'}
</Button>
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
@@ -1,12 +1,27 @@
<script> <script>
import { page } from '$app/state';
import { AppShell as SharedAppShell, ProfileDialog } from '@gabriel20xx/shared-code/web-ui';
import { Tooltip } from 'bits-ui'; import { Tooltip } from 'bits-ui';
import Header from '$lib/components/Header.svelte';
import AuthPage from '$lib/features/auth/AuthPage.svelte'; import AuthPage from '$lib/features/auth/AuthPage.svelte';
import { createAuthStore } from '$lib/features/auth/auth.svelte.js'; import { createAuthStore } from '$lib/features/auth/auth.svelte.js';
import SettingsDialog from './SettingsDialog.svelte';
let { children } = $props(); let { children } = $props();
const auth = createAuthStore(); const auth = createAuthStore();
const navItems = [
{ href: '/', label: 'Overview' },
{ href: '/about', label: 'About' },
];
let settingsOpen = $state(false);
let credentialsOpen = $state(false);
async function saveProfile(input) {
await auth.updateCredentials({
newUsername: input.username.trim() || undefined,
newEmail: input.email.trim() || undefined,
newPassword: input.password || undefined,
});
}
</script> </script>
<Tooltip.Provider delayDuration={300}> <Tooltip.Provider delayDuration={300}>
@@ -19,11 +34,27 @@
{:else if !auth.status || auth.status.setupRequired || !auth.status.authenticated} {:else if !auth.status || auth.status.setupRequired || !auth.status.authenticated}
<AuthPage setupRequired={auth.status?.setupRequired ?? true} /> <AuthPage setupRequired={auth.status?.setupRequired ?? true} />
{:else} {:else}
<div class="flex min-h-screen flex-col"> <SharedAppShell
<Header /> brand="CollabTable"
<main class="flex min-w-0 flex-1 flex-col"> currentPath={page.url.pathname}
{navItems}
theme="system"
username={auth.status.username ?? ''}
onLogout={() => auth.logout()}
onProfile={() => (credentialsOpen = true)}
onSettings={() => (settingsOpen = true)}
>
{#snippet children()}
{@render children?.()} {@render children?.()}
</main> {/snippet}
</div> </SharedAppShell>
{/if} {/if}
</Tooltip.Provider> </Tooltip.Provider>
<SettingsDialog bind:open={settingsOpen} />
<ProfileDialog
bind:open={credentialsOpen}
currentUsername={auth.status?.username ?? ''}
currentEmail={auth.status?.email ?? ''}
onSave={saveProfile}
/>
@@ -1,7 +1,7 @@
<script> <script>
import { Moon, Sun, SunMoon } from '@lucide/svelte'; import { Moon, Sun, SunMoon } from '@lucide/svelte';
import Button from '$lib/components/ui/button.svelte'; import Button from '$lib/components/ui/button.svelte';
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '$lib/components/ui/dialog'; import { SettingsDialog as SharedSettingsDialog } from '@gabriel20xx/shared-code/web-ui';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '$lib/components/ui/select'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '$lib/components/ui/select';
import { currentLanguage, languages, setLanguage } from '$lib/language.svelte.js'; import { currentLanguage, languages, setLanguage } from '$lib/language.svelte.js';
import { themeState } from '$lib/theme.svelte.js'; import { themeState } from '$lib/theme.svelte.js';
@@ -11,11 +11,7 @@
const languageItems = languages.map((language) => ({ value: language.id, label: language.label })); const languageItems = languages.map((language) => ({ value: language.id, label: language.label }));
</script> </script>
<Dialog bind:open> <SharedSettingsDialog bind:open title="Settings">
<DialogContent>
<DialogHeader>
<DialogTitle>Settings</DialogTitle>
</DialogHeader>
<div> <div>
<span class="mb-2 block text-sm font-medium">Theme</span> <span class="mb-2 block text-sm font-medium">Theme</span>
<div class="flex w-full rounded-md border border-border p-1"> <div class="flex w-full rounded-md border border-border p-1">
@@ -69,8 +65,7 @@
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>
<DialogFooter> <div class="sc-form-actions">
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button> <Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
</DialogFooter> </div>
</DialogContent> </SharedSettingsDialog>
</Dialog>
+1
View File
@@ -1,5 +1,6 @@
<script> <script>
import '../app.css'; import '../app.css';
import '@gabriel20xx/shared-code/web-ui/styles.css';
import '$lib/theme.svelte.js'; import '$lib/theme.svelte.js';
import { QueryClientProvider } from '@tanstack/svelte-query'; import { QueryClientProvider } from '@tanstack/svelte-query';
import { queryClient } from '$lib/query/queryClient.js'; import { queryClient } from '$lib/query/queryClient.js';