Skip to content

Commit

Permalink
add dev auth and account page (#54)
Browse files Browse the repository at this point in the history
* add dev login

* refresh migrations

* add account page placeholder

* chore: Update dev-login page to use window.location instead of goto() since csr doesnt update with session

* Update header link to "My Account" instead of "About"

* make one button for dev login

* use only email field
  • Loading branch information
gursheyss authored May 25, 2024
1 parent ff4c870 commit fe846cd
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 357 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
- name: Remove dev-login route
run: rm -rf src/routes/dev-login
- name: Build
run: bun run build
- name: Format
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"lucide-svelte": "^0.359.0",
"oslo": "^1.1.3",
"postgres": "^3.4.3",
"svelte-sonner": "^0.3.24",
"tailwind-variants": "^0.2.0"
}
}
8 changes: 6 additions & 2 deletions src/lib/components/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
import { Menu } from 'lucide-svelte';
import Login from '$lib/components/Login.svelte';
import Logout from '$lib/components/Logout.svelte';
import Search, { type Course } from '$lib/components/Search.svelte';
import type { User } from 'lucia';
import type { Infer, SuperValidated } from 'sveltekit-superforms';
import type { SearchSchema } from '$lib/forms/schema';
import { page } from '$app/stores';
import { dev } from '$app/environment';
type Props = {
user: User | undefined;
Expand All @@ -25,9 +25,11 @@
<Search {courses} {formData} />
{/if}
<div class="menu menu-horizontal hidden gap-x-4 lg:flex">
<a href="/about" class="btn btn-ghost btn-sm text-lg">About</a>
<a href="/account" class="btn btn-ghost btn-sm text-lg">My Account</a>
{#if user}
<Logout><button type="submit" class="btn btn-accent btn-sm text-lg">Log Out</button></Logout>
{:else if dev}
<a href="/dev-login" class="btn btn-ghost btn-sm text-lg">Dev Login</a>
{:else}
<Login><button type="submit" class="btn btn-ghost btn-sm text-lg">Log In</button></Login>
<Login><button type="submit" class="btn btn-accent btn-sm text-lg">Sign Up</button></Login>
Expand All @@ -44,6 +46,8 @@
<li><a href="/about" class="text-lg">About</a></li>
{#if user}
<li><Logout><button type="submit" class="text-lg">Log Out</button></Logout></li>
{:else if dev}
<a href="/dev-login" class="btn btn-ghost btn-sm text-lg">Dev Login</a>
{:else}
<div>
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS "professors" (
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "reviews" (
"id" serial PRIMARY KEY NOT NULL,
"userId" varchar NOT NULL,
"professor_id" integer NOT NULL,
"rating" integer NOT NULL,
Expand All @@ -37,42 +38,43 @@ CREATE TABLE IF NOT EXISTS "users" (
"id" varchar(15) PRIMARY KEY NOT NULL,
"username" text NOT NULL,
"email" text NOT NULL,
"googleId" varchar(21) NOT NULL,
"createdAt" timestamp NOT NULL
"googleId" varchar(21),
"createdAt" timestamp NOT NULL,
CONSTRAINT "users_username_unique" UNIQUE("username")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "professors_courses" ADD CONSTRAINT "professors_courses_professor_id_professors_id_fk" FOREIGN KEY ("professor_id") REFERENCES "professors"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "professors_courses" ADD CONSTRAINT "professors_courses_professor_id_professors_id_fk" FOREIGN KEY ("professor_id") REFERENCES "public"."professors"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "professors_courses" ADD CONSTRAINT "professors_courses_course_id_courses_id_fk" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "professors_courses" ADD CONSTRAINT "professors_courses_course_id_courses_id_fk" FOREIGN KEY ("course_id") REFERENCES "public"."courses"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_professor_id_professors_id_fk" FOREIGN KEY ("professor_id") REFERENCES "professors"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_professor_id_professors_id_fk" FOREIGN KEY ("professor_id") REFERENCES "public"."professors"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_course_id_courses_id_fk" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_course_id_courses_id_fk" FOREIGN KEY ("course_id") REFERENCES "public"."courses"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
1 change: 0 additions & 1 deletion src/lib/db/migrations/0001_nebulous_wrecker.sql

This file was deleted.

36 changes: 25 additions & 11 deletions src/lib/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "87a17e63-1308-43ff-bbc8-da953cd416c7",
"id": "5e051c57-44aa-47d6-9896-44fc4180217e",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
"version": "6",
"dialect": "postgresql",
"tables": {
"courses": {
"public.courses": {
"name": "courses",
"schema": "",
"columns": {
Expand Down Expand Up @@ -44,7 +44,7 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"professors_courses": {
"public.professors_courses": {
"name": "professors_courses",
"schema": "",
"columns": {
Expand Down Expand Up @@ -101,7 +101,7 @@
},
"uniqueConstraints": {}
},
"professors": {
"public.professors": {
"name": "professors",
"schema": "",
"columns": {
Expand Down Expand Up @@ -129,10 +129,16 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"reviews": {
"public.reviews": {
"name": "reviews",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"userId": {
"name": "userId",
"type": "varchar",
Expand Down Expand Up @@ -215,7 +221,7 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"sessions": {
"public.sessions": {
"name": "sessions",
"schema": "",
"columns": {
Expand Down Expand Up @@ -257,7 +263,7 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"users": {
"public.users": {
"name": "users",
"schema": "",
"columns": {
Expand All @@ -283,7 +289,7 @@
"name": "googleId",
"type": "varchar(21)",
"primaryKey": false,
"notNull": true
"notNull": false
},
"createdAt": {
"name": "createdAt",
Expand All @@ -295,7 +301,15 @@
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
"uniqueConstraints": {
"users_username_unique": {
"name": "users_username_unique",
"nullsNotDistinct": false,
"columns": [
"username"
]
}
}
}
},
"enums": {},
Expand Down
Loading

0 comments on commit fe846cd

Please sign in to comment.