Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4bbbbe4
2 set up global styles and design tokens (#3)
olestan Sep 28, 2026
952c790
5 add shared icon library (#6)
olestan Sep 29, 2026
17b61c7
Add foundational UI components (#8)
olestan Sep 30, 2026
7208035
Add form navigation UI components (#10)
olestan Oct 1, 2026
81172c7
9 build the app shell and core routes (#11)
oliveror Oct 1, 2026
b57179f
Add feedback overlay UI components (#13)
olestan Oct 2, 2026
0ea1b9e
feature(recipes): add recipe models and mock dataset (#15)
hasanmo Oct 2, 2026
cde19d3
feature(auth): implement D1-05 mock authentication flow (#17)
hasanmo Oct 2, 2026
0636381
Add reusable RecipeCard and recipe metadata components (#18)
olestan Oct 2, 2026
decbb64
comment(docs): add project concept and setup guide (#19)
hasanmo Oct 2, 2026
d849513
style: fix Prettier formatting
Oct 2, 2026
45a454f
Merge branch 'main' into dev
hasanmo Oct 2, 2026
d7f73ee
style: fix Prettier formatting
Oct 2, 2026
0eb6b2e
test: align quality checks with auth pages
Oct 2, 2026
562818a
fix(deploy): retry API health check during startup (#22)
hasanmo Oct 3, 2026
1630678
Add Explore-page with pagination and search (#26)
olestan Oct 3, 2026
02d049d
Explore filters, URL state, and Save to Cookbook (#31)
olestan Oct 7, 2026
2ee4ecc
35 frontend for add recipe (#40)
oliveror Oct 8, 2026
aa69541
Implement My Cookbook Frontend with Mock Data (#43)
olestan Oct 11, 2026
36656a9
refactor(header): use LogoMark and LinkButton (#45)
olestan Oct 11, 2026
0376c64
D1-14: Implement Recipe Detail (#46)
olestan Oct 11, 2026
bde18ec
Hasan/feat/database auth (#41)
hasanmo Oct 11, 2026
b96ffc4
Added 404-handling and Not Found Page
olestan Oct 12, 2026
bc7bccc
Hasan/feat/database model (#47)
hasanmo Oct 12, 2026
001b617
merge: reconcile main history while preserving dev
Oct 12, 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
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ nvm install
nvm use
```

For første leveranse kan frontend kjøres alene fordi oppskrifter og autentisering foreløpig er mocket:
Oppskriftsvisningen kan kjøres med frontend alene. Innlogging og registrering krever API og PostgreSQL:

```bash
npm run dev:web
Expand All @@ -59,6 +59,22 @@ Copy-Item .env.example .env

Ikke legg `.env`, passord, tokens eller andre hemmeligheter i Git.

## Authentication

Registration, login and logout use GraphQL and PostgreSQL. Both the API and database must be running; recipe browsing still uses mock data. Configure DATABASE_URL in .env and run `npm run db:migrate` before starting the API. User and session creation run in one transaction, so a failed session insert rolls back the new user.

Session tokens are bearer credentials stored in localStorage to restore login after refresh or reopening the browser. They expire after seven days and are deleted server-side on successful logout. Temporary API or network errors preserve the local token for a later restoration attempt; only a confirmed invalid or expired session clears it.

Security trade-off: localStorage is readable by JavaScript on the same origin. An XSS vulnerability could steal a token and let an attacker impersonate its owner until expiry or revocation. This prototype accepts that limitation; production deployment should use HTTPS and consider Secure, HttpOnly, SameSite cookies with appropriate CSRF protection. HttpOnly cookies prevent JavaScript from reading the session credential.

### Protected routes

`/cookbook` and `/recipes/new` require a validated session. On refresh, the router waits for session restoration before rendering protected content or redirecting to login. A temporary API/network error shows a retry action and preserves the token. Successful login or registration returns to the requested protected URL, including its query and hash. Explore and recipe details remain public. This is client-side routing; future protected API operations must enforce authentication and ownership on the server.

## Database

Se [databasemodellen](docs/database-model.md) for tabeller, ER-diagram, regler, migrasjon og tester. Modellen utvider autentiseringen og er klar for CRUD i neste steg.

## Nyttige kommandoer

| Kommando | Bruk |
Expand Down Expand Up @@ -103,8 +119,8 @@ Oppskrifter kan være offentlige eller private. Offentlige oppskrifter finnes gj
| `/cookbook` | My Cookbook: lagrede og egenproduserte oppskrifter |
| `/recipes/:id` | Detaljvisning av én oppskrift |
| `/recipes/new` | Skjema for å opprette en oppskrift |
| `/login` | Mock innlogging |
| `/register` | Mock registrering |
| `/login` | Innlogging via GraphQL |
| `/register` | Registrering via GraphQL |

### Viktige brukerreiser

Expand Down
16 changes: 16 additions & 0 deletions apps/api/migrations/0001_familiar_shocker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE "project2"."sessions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" uuid NOT NULL,
"expires_at" timestamp with time zone NOT NULL
);
--> statement-breakpoint
CREATE TABLE "project2"."users" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" text NOT NULL,
"email" text NOT NULL,
"password_hash" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "project2"."sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "project2"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "users_email_unique" ON "project2"."users" USING btree ("email");
105 changes: 105 additions & 0 deletions apps/api/migrations/0002_recipe_model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
-- Existing placeholder recipes need a deliberate author/content backfill.
-- Stop before changing tables rather than inventing ownership or losing data.
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM "project2"."recipes") THEN
RAISE EXCEPTION 'Recipe migration requires an empty legacy recipes table. Back up existing rows and prepare an explicit author/content backfill before retrying.';
END IF;
END $$;
--> statement-breakpoint
CREATE TABLE "project2"."ratings" (
"user_id" uuid NOT NULL,
"recipe_id" uuid NOT NULL,
"score" integer NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "ratings_user_id_recipe_id_pk" PRIMARY KEY("user_id","recipe_id"),
CONSTRAINT "ratings_score_valid" CHECK ("project2"."ratings"."score" BETWEEN 1 AND 5)
);
--> statement-breakpoint
CREATE TABLE "project2"."recipe_ingredients" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"recipe_id" uuid NOT NULL,
"name" text NOT NULL,
"amount" numeric(12, 4) NOT NULL,
"unit" text NOT NULL,
"note" text,
"position" integer NOT NULL,
CONSTRAINT "recipe_ingredients_name_not_blank" CHECK (length(trim("project2"."recipe_ingredients"."name")) > 0),
CONSTRAINT "recipe_ingredients_amount_positive" CHECK ("project2"."recipe_ingredients"."amount" > 0 AND "project2"."recipe_ingredients"."amount" <> 'NaN'::numeric),
CONSTRAINT "recipe_ingredients_position_positive" CHECK ("project2"."recipe_ingredients"."position" > 0)
);
--> statement-breakpoint
CREATE TABLE "project2"."recipe_instructions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"recipe_id" uuid NOT NULL,
"text" text NOT NULL,
"position" integer NOT NULL,
CONSTRAINT "recipe_instructions_text_not_blank" CHECK (length(trim("project2"."recipe_instructions"."text")) > 0),
CONSTRAINT "recipe_instructions_position_positive" CHECK ("project2"."recipe_instructions"."position" > 0)
);
--> statement-breakpoint
CREATE TABLE "project2"."recipe_tags" (
"recipe_id" uuid NOT NULL,
"tag" text NOT NULL,
CONSTRAINT "recipe_tags_recipe_id_tag_pk" PRIMARY KEY("recipe_id","tag"),
CONSTRAINT "recipe_tags_normalized" CHECK (length("project2"."recipe_tags"."tag") > 0 AND "project2"."recipe_tags"."tag" = lower(trim("project2"."recipe_tags"."tag")))
);
--> statement-breakpoint
CREATE TABLE "project2"."saved_recipes" (
"user_id" uuid NOT NULL,
"recipe_id" uuid NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "saved_recipes_user_id_recipe_id_pk" PRIMARY KEY("user_id","recipe_id")
);
--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "author_id" uuid NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "description" text NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "image_url" text;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "category" text NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "cuisine" text NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "difficulty" text NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "visibility" text DEFAULT 'private' NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "prep_minutes" integer NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "cook_minutes" integer NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "servings" integer NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "created_at" timestamp with time zone DEFAULT now() NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "updated_at" timestamp with time zone DEFAULT now() NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."ratings" ADD CONSTRAINT "ratings_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "project2"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project2"."ratings" ADD CONSTRAINT "ratings_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "project2"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project2"."recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "project2"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project2"."recipe_instructions" ADD CONSTRAINT "recipe_instructions_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "project2"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project2"."recipe_tags" ADD CONSTRAINT "recipe_tags_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "project2"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project2"."saved_recipes" ADD CONSTRAINT "saved_recipes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "project2"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project2"."saved_recipes" ADD CONSTRAINT "saved_recipes_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "project2"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "ratings_recipe_idx" ON "project2"."ratings" USING btree ("recipe_id");--> statement-breakpoint
CREATE UNIQUE INDEX "recipe_ingredients_recipe_position_unique" ON "project2"."recipe_ingredients" USING btree ("recipe_id","position");--> statement-breakpoint
CREATE UNIQUE INDEX "recipe_instructions_recipe_position_unique" ON "project2"."recipe_instructions" USING btree ("recipe_id","position");--> statement-breakpoint
CREATE INDEX "saved_recipes_recipe_idx" ON "project2"."saved_recipes" USING btree ("recipe_id");--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "project2"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "recipes_author_idx" ON "project2"."recipes" USING btree ("author_id");--> statement-breakpoint
CREATE INDEX "recipes_public_created_idx" ON "project2"."recipes" USING btree ("created_at","id") WHERE "project2"."recipes"."visibility" = 'public';--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_title_not_blank" CHECK (length(trim("project2"."recipes"."title")) > 0);--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_category_not_blank" CHECK (length(trim("project2"."recipes"."category")) > 0);--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_cuisine_not_blank" CHECK (length(trim("project2"."recipes"."cuisine")) > 0);--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_difficulty_valid" CHECK ("project2"."recipes"."difficulty" IN ('easy', 'medium', 'hard'));--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_visibility_valid" CHECK ("project2"."recipes"."visibility" IN ('public', 'private'));--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_prep_minutes_nonnegative" CHECK ("project2"."recipes"."prep_minutes" >= 0);--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_cook_minutes_nonnegative" CHECK ("project2"."recipes"."cook_minutes" >= 0);--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_servings_positive" CHECK ("project2"."recipes"."servings" > 0);
--> statement-breakpoint
-- Database triggers also cover writes made through raw SQL (as in auth).
CREATE FUNCTION "project2"."touch_updated_at"() RETURNS trigger
LANGUAGE plpgsql AS $$
BEGIN
NEW.updated_at = clock_timestamp();
RETURN NEW;
END $$;
--> statement-breakpoint
CREATE TRIGGER recipes_touch_updated_at
BEFORE UPDATE ON "project2"."recipes"
FOR EACH ROW EXECUTE FUNCTION "project2"."touch_updated_at"();
--> statement-breakpoint
CREATE TRIGGER ratings_touch_updated_at
BEFORE UPDATE ON "project2"."ratings"
FOR EACH ROW EXECUTE FUNCTION "project2"."touch_updated_at"();
10 changes: 10 additions & 0 deletions apps/api/migrations/0003_recipe_review.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ALTER TABLE "project2"."recipes" DROP CONSTRAINT "recipes_category_not_blank";--> statement-breakpoint
ALTER TABLE "project2"."recipes" ALTER COLUMN "cuisine" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD COLUMN "source_recipe_id" uuid;--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_source_recipe_id_recipes_id_fk" FOREIGN KEY ("source_recipe_id") REFERENCES "project2"."recipes"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "recipes_source_idx" ON "project2"."recipes" USING btree ("source_recipe_id");--> statement-breakpoint
-- Normalize known category labels without guessing mappings for unknown values.
-- Unknown categories abort the migration and require an explicit correction.
UPDATE "project2"."recipes" SET "category" = lower(trim("category"))
WHERE "category" <> lower(trim("category"));--> statement-breakpoint
ALTER TABLE "project2"."recipes" ADD CONSTRAINT "recipes_category_valid" CHECK ("project2"."recipes"."category" IN ('breakfast', 'lunch', 'dinner', 'dessert', 'soup'));
149 changes: 149 additions & 0 deletions apps/api/migrations/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"id": "8106c561-4f83-4ec4-9119-840e77bd557d",
"prevId": "fa9889d1-8b19-437d-8360-333cd24d5aea",
"version": "7",
"dialect": "postgresql",
"tables": {
"project2.recipes": {
"name": "recipes",
"schema": "project2",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"project2.sessions": {
"name": "sessions",
"schema": "project2",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"expires_at": {
"name": "expires_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"sessions_user_id_users_id_fk": {
"name": "sessions_user_id_users_id_fk",
"tableFrom": "sessions",
"tableTo": "users",
"schemaTo": "project2",
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"project2.users": {
"name": "users",
"schema": "project2",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"password_hash": {
"name": "password_hash",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"users_email_unique": {
"name": "users_email_unique",
"columns": [
{
"expression": "email",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
Loading