Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3a00201
Claim frontend task F2 (auth) in the backlog
Filionus Nov 26, 2026
b091056
Add Pinia and run tests in stores, composables and middleware
Filionus Nov 26, 2026
cf485d7
Pin language switching inside the default layout
Filionus Nov 26, 2026
6ba52db
Add tests for the session store
Filionus Nov 26, 2026
c7b3395
Add test for fetching a token while the server is unreachable
Filionus Nov 26, 2026
bfeb70b
Add the session store
Filionus Nov 26, 2026
7f108e3
Add tests for route protection and client-only app pages
Filionus Nov 26, 2026
8dcf6ba
Protect pages and render the app in the browser (F2)
Filionus Nov 26, 2026
16751da
Add tests for the API client and error messages
Filionus Nov 26, 2026
d9e8d25
Add the API client and translated error messages (F2)
Filionus Nov 26, 2026
1a146a5
Add contrast checks for error text and form field borders
Filionus Nov 26, 2026
cdbe7b2
Add danger and field colour tokens
Filionus Nov 26, 2026
cc086b5
Add tests for the login and registration forms
Filionus Nov 26, 2026
1e3ea7a
Add accessible login and registration forms (F2)
Filionus Nov 26, 2026
7636949
Add tests for the session controls and the sign-in return page
Filionus Nov 26, 2026
4451890
Add sign-out, the signed-in header and the sign-in return page (F2)
Filionus Nov 26, 2026
652fd9b
Add tests for the language of the page after signing in
Filionus Nov 26, 2026
92dbc76
Return to the requested page in the language of the login page
Filionus Nov 26, 2026
d0b16d7
Record the auth and rendering decisions in the agent guide
Filionus Nov 26, 2026
0f4c09a
Add tests for a switched-off Google provider
Filionus Nov 26, 2026
fa0fdbd
Stay in the app when Google sign-in is switched off
Filionus Nov 26, 2026
bcd34ae
Add tests for a minimum password length of 8
Filionus Nov 26, 2026
d8a5389
Require passwords of at least 8 characters
Filionus Nov 26, 2026
20617d0
Update the agent guide for the password length
Filionus Nov 26, 2026
86afa9c
Add tests for an unlocalized callback page without the i18n macro
Filionus Nov 26, 2026
68ad649
Unlocalize the callback page in the i18n config
Filionus Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ Course milestones: working prototype for Business Angel Meeting II (December), p
- Supabase: Postgres, Auth (email/password, Google), private Storage
- Deployment target: Vercel (app) + Supabase (backend services), free tiers
- Backend prototype exists and is being hardened (see `docs/BACKLOG.md`).
The frontend has an app shell (layout, navigation, design tokens, DE/EN/NL); the feature pages are placeholders.
The frontend has an app shell (layout, navigation, design tokens, DE/EN/NL) and sign-in (F2); the feature pages
are placeholders.
- Frontend stack from `docs/Lastenheft_Ons.md`: Pinia, `@nuxtjs/i18n` (DE/EN/NL), Tailwind or UnoCSS,
Leaflet or MapLibre, Chart.js or ECharts. The frontend dev decides between the "or" options and records the
choice here. A new dependency goes in `package.json`, a shared file: say why in the PR description.
- Decided: styling uses **Tailwind CSS v4** (`tailwindcss` with `@tailwindcss/vite`). Design tokens are plain CSS
variables, so the look can be changed without knowing Tailwind (see Frontend rules).
- Decided: `@nuxtjs/i18n` is pinned to exactly **10.2.3**. Later releases require `vue-router` 5, while Nuxt 3.21
ships version 4. Do not upgrade it without moving to a Nuxt version that matches.
- Not installed yet: Pinia, the map library and the chart library.
- Decided: **Pinia** (`pinia` 3 with `@pinia/nuxt` 0.11) holds client state, starting with the session.
- Decided: **rendering.** Only the landing page (`/`, `/en`, `/nl`) is rendered on the server. Every other page is
rendered in the browser (`routeRules` in `nuxt.config.ts`), because the Supabase session is stored there.
- Not installed yet: the map library and the chart library.

## Ownership (who works where)

Expand Down Expand Up @@ -104,6 +108,9 @@ no mocking of the unit under test. Keep tests fast and independent of each other
Vitest is the single runner for unit, component and database tests (`npm test`). Playwright for E2E is not set up yet.
Backend tests live in `tests/`. Frontend tests live in `__tests__/` folders next to the code: `*.nuxt.spec.ts`
runs inside a Nuxt runtime, other `*.spec.ts` files run in plain Node (see `vitest.config.ts`).
Shared test helpers live in `composables/__tests__/` (for example `fake-auth.ts`, an in-memory Supabase Auth).
Put only spec files into `pages/__tests__/` and `components/__tests__/`: Nuxt would register other files there as
pages or components.
"Done" always includes: new behavior has a test, and `npm test` and `npm run build` pass.

## Backend rules (do not break these)
Expand Down Expand Up @@ -147,6 +154,14 @@ Rule 1 applies to everyone, including the frontend.
- **Date categories** are fixed keys from `shared/date-categories.ts`; their labels come from i18n by key.
- Auth: the Supabase client is provided as `useNuxtApp().$supabase` (client only, see `plugins/auth.client.ts`).
Protect pages with route middleware, not with `v-if` in components.
- `middleware/auth.global.ts` protects **every** page. A page opts out with
`definePageMeta({ access: 'public' })` or `access: 'guest'` (only for signed-out visitors).
- Reach Supabase Auth only through `composables/useSupabaseAuth.ts`. The session state is in `stores/session.ts`.
- Call the API only through `useApi()` and show a failure with `t(error.messageKey)`.
- A `redirect` query value goes through `useReturnTarget()`, which only accepts paths inside the app.
- Google sign-in and confirmation emails return to `/auth/callback` (one address, no language prefix).
- Passwords need at least 8 characters. `PASSWORD_MIN_LENGTH` in `composables/formRules.ts` and
`minimum_password_length` under `[auth]` in `supabase/config.toml` must match; a frontend test fails otherwise.

## Current data model

Expand Down
3 changes: 3 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<script setup lang="ts">
const { t, localeProperties } = useI18n()

// Sends people away from protected pages when their session ends.
useLeaveWhenSignedOut()

// Keeps <html lang> in step with the active language (screen readers, browser translation).
// SEO tags such as hreflang are left out until F10, because they need a fixed base URL.
useHead({
Expand Down
7 changes: 6 additions & 1 deletion assets/__tests__/contrast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ const pairs: [string, string, number][] = [
['accent', 'canvas', 4.5],
['accent', 'surface', 4.5],
['on-accent', 'accent', 4.5],
// Focus rings are not text, so 3:1 is enough.
// Error messages are text.
['danger', 'canvas', 4.5],
['danger', 'surface', 4.5],
// Focus rings and the borders of form fields are not text, so 3:1 is enough.
['focus', 'canvas', 3],
['focus', 'surface', 3],
['field', 'canvas', 3],
['field', 'surface', 3],
]

describe('design tokens', () => {
Expand Down
8 changes: 8 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
--color-muted: var(--ons-color-muted);
--color-accent: var(--ons-color-accent);
--color-on-accent: var(--ons-color-on-accent);
--color-danger: var(--ons-color-danger);
--color-field: var(--ons-color-field);

--font-*: initial;
--font-heading: var(--ons-font-heading);
Expand Down Expand Up @@ -65,6 +67,7 @@

--container-*: initial;
--container-content: var(--ons-size-content);
--container-form: var(--ons-size-form);
}

/*
Expand Down Expand Up @@ -92,6 +95,11 @@
min-height: var(--ons-size-nav);
}

/* For buttons that are waiting, as in disabled:faded. */
@utility faded {
opacity: var(--ons-opacity-disabled);
}

/* Draws the focus ring inside the element, for items that touch the screen edge. */
@utility focus-inset {
&:focus-visible {
Expand Down
13 changes: 13 additions & 0 deletions assets/css/tokens.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
--palette-sand-50: #fbf7f2;
--palette-sand-200: #e8ded2;
--palette-sand-300: #cdbfb0;
--palette-sand-600: #8a7c6c;
--palette-ink-400: #8c8196;
--palette-ink-500: #645a6b;
--palette-ink-700: #4a3f55;
--palette-ink-800: #2c2434;
Expand All @@ -26,6 +28,8 @@
--palette-plum-700: #7a3468;
--palette-blue-300: #8ec5ff;
--palette-blue-700: #1c5fb8;
--palette-red-300: #ffb4ab;
--palette-red-700: #a3261d;

/* 2. Colour roles: light-dark(light theme, dark theme). */
/* Page background */
Expand All @@ -44,6 +48,10 @@
--ons-color-on-accent: light-dark(var(--palette-white), var(--palette-ink-900));
/* Keyboard focus ring */
--ons-color-focus: light-dark(var(--palette-blue-700), var(--palette-blue-300));
/* Error messages and the border of an invalid field */
--ons-color-danger: light-dark(var(--palette-red-700), var(--palette-red-300));
/* Border of form fields and outlined buttons */
--ons-color-field: light-dark(var(--palette-sand-600), var(--palette-ink-400));

/* 3. Typography. System fonts until the brand typefaces are chosen. */
--ons-font-heading: ui-serif, Georgia, 'Times New Roman', serif;
Expand Down Expand Up @@ -87,6 +95,11 @@
--ons-size-nav: 3.5rem;
/* Widest content column */
--ons-size-content: 64rem;
/* Widest form */
--ons-size-form: 24rem;

/* How strongly a button fades while it is waiting */
--ons-opacity-disabled: 0.6;
}

/* Hooks for a manual theme switch. Nothing sets data-theme yet. */
Expand Down
2 changes: 1 addition & 1 deletion components/AppNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { t } = useI18n()

// The main pages. To plug in a new one, add its file in pages/ and one entry here.
const items = [
{ to: '/', label: 'nav.home' },
{ to: '/dashboard', label: 'nav.dashboard' },
{ to: '/dates', label: 'nav.dates' },
{ to: '/map', label: 'nav.map' },
{ to: '/photos', label: 'nav.photos' },
Expand Down
157 changes: 157 additions & 0 deletions components/CredentialsForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<script setup lang="ts">
// Email and password form plus the Google button, used by the login and register pages.
const props = defineProps<{
mode: 'login' | 'register'
}>()

const { t } = useI18n()
const session = useSessionStore()
const route = useRoute()
const returnTarget = useReturnTarget()

const email = ref('')
const password = ref('')
// Message keys, so the texts follow a language change.
const errors = reactive<{ email?: string, password?: string }>({})
const failure = ref<string>()
const confirmationSentTo = ref<string>()
const pending = ref(false)

const emailField = useTemplateRef('emailField')
const passwordField = useTemplateRef('passwordField')

const isRegistration = computed(() => props.mode === 'register')

function translate(key: string | undefined) {
return key ? t(key, { min: PASSWORD_MIN_LENGTH }) : undefined
}

function validate() {
errors.email = emailError(email.value)
errors.password = isRegistration.value ? newPasswordError(password.value) : passwordError(password.value)
return !errors.email && !errors.password
}

// Runs one request: blocks further clicks and turns failures into a message.
async function attempt(request: () => Promise<void>) {
if (pending.value) {
return
}
pending.value = true
failure.value = undefined
try {
await request()
}
catch (error) {
failure.value = authErrorKey(error instanceof AuthFailure ? error.code : undefined)
}
finally {
pending.value = false
}
}

function openRequestedPage() {
return navigateTo(returnTarget(route.query.redirect))
}

async function submit() {
if (!validate()) {
// Move focus to the first field that needs attention, once it is marked as invalid.
await nextTick()
const firstInvalid = errors.email ? emailField.value : passwordField.value
firstInvalid?.focus()
return
}
const address = email.value.trim()

await attempt(async () => {
if (!isRegistration.value) {
await session.signIn(address, password.value)
await openRequestedPage()
return
}
if (await session.register(address, password.value) === 'confirmationRequired') {
confirmationSentTo.value = address
return
}
await openRequestedPage()
})
}

function continueWithGoogle() {
// Supabase now leaves the app for Google and comes back to /auth/callback.
return attempt(() => session.signInWithGoogle())
}
</script>

<template>
<div class="mt-4 flex max-w-form flex-col gap-4">
<p
v-if="confirmationSentTo"
role="status"
class="rounded-md border border-field bg-surface p-4"
>
{{ t('auth.confirmationSent', { email: confirmationSentTo }) }}
</p>

<template v-else>
<p
v-if="failure"
role="alert"
class="rounded-md border-2 border-danger bg-surface p-4 text-danger"
>
{{ t(failure) }}
</p>

<!-- novalidate: the app shows its own messages, in the chosen language. -->
<form
class="flex flex-col gap-4"
method="post"
novalidate
@submit.prevent="submit"
>
<FormField
ref="emailField"
v-model="email"
type="email"
autocomplete="email"
:label="t('auth.email')"
:error="translate(errors.email)"
/>
<FormField
ref="passwordField"
v-model="password"
type="password"
:autocomplete="isRegistration ? 'new-password' : 'current-password'"
:label="t('auth.password')"
:hint="isRegistration ? t('auth.passwordHint', { min: PASSWORD_MIN_LENGTH }) : undefined"
:error="translate(errors.password)"
/>
<button
type="submit"
:disabled="pending"
class="min-h-touch rounded-md bg-accent px-4 font-strong text-on-accent disabled:cursor-wait disabled:faded"
>
{{ isRegistration ? t('auth.createAccount') : t('auth.signIn') }}
</button>
</form>

<button
type="button"
:disabled="pending"
class="min-h-touch rounded-md border border-field bg-surface px-4 font-strong disabled:cursor-wait disabled:faded"
@click="continueWithGoogle"
>
{{ t('auth.google') }}
</button>
</template>

<!-- The other form, keeping the return address. -->
<NuxtLinkLocale
:to="{ path: isRegistration ? '/login' : '/register', query: route.query }"
class="inline-flex min-h-touch items-center text-accent underline"
>
{{ isRegistration ? t('auth.haveAccount') : t('auth.noAccount') }}
</NuxtLinkLocale>
</div>
</template>
56 changes: 56 additions & 0 deletions components/FormField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script setup lang="ts">
// A labelled input with an optional hint and an error message.
// Screen readers hear hint and error through aria-describedby.
const props = defineProps<{
label: string
type: 'email' | 'password' | 'text'
autocomplete: string
hint?: string
error?: string
}>()

const value = defineModel<string>({ required: true })

const id = useId()
const input = useTemplateRef<HTMLInputElement>('input')

const describedBy = computed(() => {
const ids = [props.hint && `${id}-hint`, props.error && `${id}-error`].filter(Boolean)
return ids.length ? ids.join(' ') : undefined
})

defineExpose({ focus: () => input.value?.focus() })
</script>

<template>
<div class="flex flex-col gap-1">
<label
:for="id"
class="text-sm font-strong"
>{{ props.label }}</label>
<input
:id="id"
ref="input"
v-model="value"
:type="props.type"
:autocomplete="props.autocomplete"
:aria-invalid="props.error ? 'true' : undefined"
:aria-describedby="describedBy"
class="min-h-touch w-full rounded-md border border-field bg-surface px-3 text-base text-ink aria-invalid:border-2 aria-invalid:border-danger"
>
<p
v-if="props.hint"
:id="`${id}-hint`"
class="text-sm text-muted"
>
{{ props.hint }}
</p>
<p
v-if="props.error"
:id="`${id}-error`"
class="text-sm text-danger"
>
{{ props.error }}
</p>
</div>
</template>
26 changes: 26 additions & 0 deletions components/SessionControls.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script setup lang="ts">
// Sign-in link or sign-out button in the header. Empty until the session is known,
// so the server-rendered landing page and the browser start out the same.
const { t } = useI18n()
const session = useSessionStore()
</script>

<template>
<div class="flex min-h-touch items-center">
<NuxtLinkLocale
v-if="session.status === 'signedOut'"
to="/login"
class="inline-flex min-h-touch items-center px-2 text-sm font-strong text-accent underline"
>
{{ t('auth.signIn') }}
</NuxtLinkLocale>
<button
v-else-if="session.isSignedIn"
type="button"
class="min-h-touch rounded-md border border-field px-3 text-sm font-strong"
@click="session.signOut()"
>
{{ t('auth.signOut') }}
</button>
</div>
</template>
Loading
Loading